1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Need a help about making prediction shots

Discussion in 'Programming' started by hijong park, Mar 14, 2019.

  1. hijong park

    hijong park Member

    Joined:
    Dec 29, 2016
    Posts:
    114
    I'm trying to implement prediction shot for the enemies to make it more challenging. I did some experiments with point_distance and lengthdir_x / lengthdir_y to make it, but It never worked well. So I searched for prediction shot examples and found this one:



    Code:
    predir = point_direction(x,y,player.x,player.y)
    
    alpha = object0.speed / shootspeed;
    phi = degtorad(object0.direction - predir);
    beta = alpha * sin(phi);
    if (abs(beta) >= 1) {
    return (-1);
    }
    predir += radtodeg(arcsin(beta));


    This one works precisely, which is good. But the problem is that this method only gets the direction of the bullet to move for prediction shots, not the x and y coordinates the bullet would move to. I need to get the positions of the predict shooting bullets, so enemies won't end up firing their bullet at the wall when there's a wall in the predicted position.

    Are there any possible ways to make the prediction shooting by getting x and y positions of it?
     
  2. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    841
    Once you have the direction, can't you use lengthdir_x and lengthdir_y to get the x and y, with len being the distance from the bullet to the coordinates of the player + his hsp/vsp.
     
  3. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    782
    Could you not just use a collision line check before firing?
     
  4. hijong park

    hijong park Member

    Joined:
    Dec 29, 2016
    Posts:
    114
    but I need x and y value of the predicted shot's position to use collision line. You might know that just checking collision line between enemy.x,enemy.y and player.x, player.y would not work well for prediction shooting, as players would exploit it by moving around in the narrow corridors to make the enemy shooting at the walls.
     
    Last edited: Mar 14, 2019
  5. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,711
    I recall you'll have to look at line intersection maths for that.
     
  6. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,931
    Using the law of sines:

    distance_to_intercept = point_distance(x, y, target.x ,target.y) * dsin(phi) / dsin(phi - darcsin(beta));
    intercept_x = x + dcos(shoot_dir) * distance_to_intercept;
    intercept_y = y - dsin(shoot_dir) * distance_to_intercept;

    shoot_dir is the direction in which you shoot the bullet.
     
  7. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    160
    Yeah it would be about the same idea and checking for the enemy x and y for collisions you just use the predicted x and y and see if the bullet can make to where you predict the player will be and if it is clear you can try to lead the shot to hit him.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice