• Advertisement
Sign in to follow this  

Missile Pathing for 2D game

This topic is 1826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

Oddly, that didnt work.

 

rotation = (float) getAngle(centerX, centerY, vx, vy);

public static double getAngle(float x1, float y1, float x2, float y2)
{
     float deltaX = x2 - x1;
     float deltaY = y2 - y1;

     return Math.atan2(deltaY, deltaX) * 180 / Math.PI;
}

Share this post


Link to post
Share on other sites

The missile's direction wouldn't be from (centerx,centery)->(vx,vy). (vx,vy) indicate the direction the missile is going. That is the direction, and that is the vector you need.

 

angle=atan2(vy,vx)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement