# Moving objects

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

## Recommended Posts

Hi, I have a an object that recieves position and orientation from an external program. In my application, wich uses an physical library, i need to move the object to this position/orientation over 10 iterations. One though is to use a spring, connected to a "dummy" object that i set the position/orientation in each iteration. My other though is to compute the force from the delta position and delta velocity. For my its really important with precision. Id really appreciate if someone had any hints, methods that could be used, or good google search woords :)

##### Share on other sites
Quote:
 Original post by ConnMy other though is to compute the force from the delta position and delta velocity.

Are you talking about a LERP? A lerp (linear interpolation) will change one value to another over time.

Tim

##### Share on other sites
Sorry that im a little unclear.
I want to use forces to move the object. Not set the position and orientation directly.
So i have to compute the forces to apply in each step.

##### Share on other sites
Does it have to arrive in Exactly 10 cycles? (most people use time units btw, since gameloop cycles vary between machines)

If arriving early is OK, you can just accelerate with max force to the halfway point, then deccelerate max force till you arrive.
(this is assuming you are in freefall, with no external forces that might bias anything...)

##### Share on other sites
What properties are you looking for in the motion?

An correctly-tuned instantanous force (implemented directly via an impulse) at frame zero will send the particle towards the target with uniform velocity (assuming no resistance). Kind of like hitting it with a baseball bat. This is continuous but not differentaible, so it's not very 'smooth' (informally) at all.

Uniformly accelerating half way there and decelerating on the way back will give piecewise-smooth parabolic motion. The peak speed will be half way along the path, and the particle will come to rest at the target. This is once differentiable, and looks smoother than the previous curve.

If you want smoother motion yet, you can look to exponantials for infinite differentiability:

A straight-forward exponential decay (perhaps with a linear component) will model a loose spring. Each frame, move the target a fixed proportion towards its target. This is about as smooth as it gets, but without a little fudging, the particle will never quite reach its target, and its initial momentum is unaccounted for.

Maybe the nicest option is simple harmonic motion about the start-finish midpoint. This will, after half a wavelength, bring the particle from rest at its start point to rest at its target with the maximum smoothness achieveable (infinitely differentiable). The force to be applied at any moment is cos(pi.x/L). You can adjust the 'spring constant' (scalar-multiply this factor) to alter the time taken to destination.

If none of these suit your needs, you can tailor a 'force' function of time to follow any continuous path you like, with a little calculus. If you only need to move in a straight line, then the displacement of the particle at any time will simply be the definite integral of the force with respect to time=0..now.

Regards

##### Share on other sites

I'm going to make the leap that 10 iterations means 10 fixed units of time and for the purposes of what follows: 10 seconds.

Let's just deal with the position of the object (orientation is similiar):

x Starting position of the object, given
v Starting velocity of the object, given
a Applied acceleration, we need to solve for this
t Time of course, given
x(t) Position of the object at time t, given

So we have: x(t) = x + v * t + 0.5 * a * t^2
And from Mr. Newton: f = ma
=> a = f / m

Which lets us write: x(t) = x + v * t + 0.5 * f/m * t^2

From here all you need to do is slove for f; you need to do this for all three dimensions of course. I would check my algebra but I believe the solution is:

f = 2*m*(x-x(t)-v*t) / t^2

Now, if you apply a force of f to your object for a period of t seconds it will arrive at location x(t) when t seconds have expired assuming it doesn't interact with anything else. Or will it? It depends on how you are integrating the equations over time. In the case above the acceleration is constant so you can actually put the object where it needs to be after each time step. Just use:

x(t) = x + v * t + 0.5 * a * t^2

But something tells me that's not an option.

If you want the object to be at position x at time t (with no error) we need to know something about your integrator and even then it might not be possible, floating point operations suffer from numerical drift period; there's not much you can do about it short of setting values manually.

##### Share on other sites
Quote:
 Original post by haphazardlynamedDoes it have to arrive in Exactly 10 cycles? (most people use time units btw, since gameloop cycles vary between machines)

Idealisticly i would love to have it arrive in 10 cycles, but im not sure that thats possible in every situation
Im using fixed time step, i do not have to wory about running the program on different machines.

Quote:
 Original post by haphazardlynamedIf arriving early is OK, you can just accelerate with max force to the halfway point, then deccelerate max force till you arrive.(this is assuming you are in freefall, with no external forces that might bias anything...)

Arriving early should be avoided. Now the object might be affected by forces ( gravitation/collision), so i need to do calculations every cycle to check the result from the last cycle

##### Share on other sites
Quote:
 Original post by TheAdmiralWhat properties are you looking for in the motion?

I would like to get a smooth motion. This method is gonna be use to move a boat, and the boat can have objects on it. Theese objects has to move with the boat ( assuming the friction coefficient is bigg enough )

##### Share on other sites
Quote:
 Original post by nonoptimalrobotI'm going to make the leap that 10 iterations means 10 fixed units of time and for the purposes of what follows: 10 seconds.

Yes 10 cycles means 10 fixed units of time, each is 0.01 second

Quote:
 Original post by nonoptimalrobotLet's just deal with the position of the object (orientation is similiar):x Starting position of the object, givenv Starting velocity of the object, givena Applied acceleration, we need to solve for thist Time of course, givenx(t) Position of the object at time t, givenSo we have: x(t) = x + v * t + 0.5 * a * t^2And from Mr. Newton: f = ma => a = f / mWhich lets us write: x(t) = x + v * t + 0.5 * f/m * t^2From here all you need to do is slove for f; you need to do this for all three dimensions of course. I would check my algebra but I believe the solution is:f = 2*m*(x-x(t)-v*t) / t^2Now, if you apply a force of f to your object for a period of t seconds it will arrive at location x(t) when t seconds have expired assuming it doesn't interact with anything else. Or will it? It depends on how you are integrating the equations over time. In the case above the acceleration is constant so you can actually put the object where it needs to be after each time step. Just use:x(t) = x + v * t + 0.5 * a * t^2But something tells me that's not an option.

I have worked some with the equations for motion, but i dont think they work well in computer physics

Quote:
 Original post by nonoptimalrobotIf you want the object to be at position x at time t (with no error) we need to know something about your integrator and even then it might not be possible, floating point operations suffer from numerical drift period; there's not much you can do about it short of setting values manually.

No from my point of view, id prolly have to do a back wards calculation, as u have mention here. Retract the acceleration from the delta position and delta velocity.
Im not sure on what integrator to use, i havent got that much experience with the different ones. I see Eulers is used alot, but it i think id like to try a more accurate solver, perhaps RK. I was hoping to get some tips on what solvers to use.

For the error question, offcourse i can live with some inaccurancy

##### Share on other sites
Quote:
 Original post by ConnI have worked some with the equations for motion, but i dont think they work well in computer physics

They've always worked well for me... better than in real life considering that computer physics are much more predictable...

I think doing equations of motion is probably your best bet. You said that the object would be operating under the influence of forces(water current?), so the freefall symmetry approach doesnt work...
the eq of motion though, has the variables of Time (defined), Force(the current+your variable), and Distance (defined). So really it does sound ideal given your problem constraints...should be solvable

Or is there a problem? is the water current randomized over time or something?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634051
• Total Posts
3015244
×