OblivionSkull21
Member
For context, it's a bullet hell game. So what I'm trying to achieve is have four bullets orbit around the player at all times until a timer hits 0, in which they will spring back and then shoot straight at the player.
The code I have now works for orbiting the player, but as soon as the player moves (the player's position changes), the orbiting gets thrown off.
I'm not sure why the orbiting messes up once the player moves... I also don't know how to go about having the bullets "spring back" and then shoot at the player. I'm not great with sin and cosin.
The code I have now works for orbiting the player, but as soon as the player moves (the player's position changes), the orbiting gets thrown off.
GML:
//initially set spawn points, so that each bullet is in a different starting position (N S E W)
if spawn{
x = player.x + new_x; //new x, new_y controlled in object creation code, they're either -40, 0, or 40
y = player.y + new_y; //new x, new_y controlled in object creation code, they're either -40, 0, or 40
spawn = false; //the bullets have been spawned, don't reset them
}
else{
//distance from focal point
radius = 40;
phase = point_direction(player.x, player.y, x, y);
//speed of orbit
phase += 2;
//orbit the player
x = player.x + radius * dcos(phase);
y = player.y - radius * dsin(phase);
}
//always point toward the player
image_angle = point_direction(x,y,player.x,player.y);