Jump to content
  • Advertisement
Sign in to follow this  

Problem with rounded movement (XNA)

This topic is 2918 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

I'm trying to get an object to move smoothly (with a rounded motion) toward a point, but it's not going incredibly well.
I can get it to move straight toward the initial destination (The hump of the curve in the motion, in most cases), but when I try to update the angle constantly, to get it to round back to the final destination (The end of the curve), it moves erratically.
Here is my code for moving my object. Both of these are called every Update.
Let me know if you need any more of the code, to help determine the problem.

initdest is the "hump of the curve", which moves toward the final destination,
because I'm too lazy to actually make the object change targets.
finaldest is the final destination of the object.

public void getAngle()
//These statements are cut out,when not rounding to the second
//point, and this method is only run while initializing the object.
//This is not the problem, as I get (basically) The same effect
//without this chunk of code here
if (initdest.Y < finaldest.Y)
initdest.Y += gravity; //Gravity being the pull of "finaldest"
if (initdest.Y > finaldest.Y)
initdest.Y -= gravity;
if (initdest.X < finaldest.X)
initdest.X += gravity;
if (initdest.X > finaldest.X)
initdest.X -= gravity;

//Find the length of all of the sides of the triangle made with the
//position, and destination
double Lx = position.X - initdest.X;
double Ly = position.Y - initdest.Y;
double Lh = Math.Sqrt((Ly * Ly) + (Lx * Lx));
//Find the angle to fall at, using those lengths.
angle = (float)Math.Acos(((Ly * Ly) + (Lh * Lh) - (Lx * Lx)) / (2 * Ly * Lh));

public void move()
float slope = (float)Math.Tan(angle);
velocity.Y = -1 * slope; // Move the object Vertically
velocity.X = 1; // Move the object Horizontally
velocity *= speed; //Speed is generally just 1 for testing, anyway
position += velocity;

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!