• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Need a help about making prediction shots

hijong park

Member
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?
 

Slyddar

Member
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.
 

hijong park

Member
Could you not just use a collision line check before firing?
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:
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.
 

curato

Member
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.
 
Top