In my 2d java game, I need to move projectiles from Enemy object to Player object in a straight line. I did some research and found out that I can use atan2(x, y) method of Math class to get the angle, but then how am i supposed to move the projectile in that particular angle(direction)? Any ideas would be very helpful.
The equation of movment with constant speed is simple
positionX = startPositionX + speedX * time
positionY = startPositionX + speedY * time
where
speedX = speed * sin(angle)
speedY = speed * cos(angle)
But most of the game use incremental aproach
posX = posX + speedX / lengthOfTick
posY = posY + speedY / lengthOfTick
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.