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

## 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;
}

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
13

• 14
• 10
• 25
• 9
• 57
• ### Forum Statistics

• Total Topics
632642
• Total Posts
3007620
• ### Who's Online (See full list)

There are no registered users currently online

×