Jump to content
  • Advertisement
Sign in to follow this  
Conn

Moving objects

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

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 this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Conn
My 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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
Admiral

Share this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by haphazardlynamed
Does 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 haphazardlynamed
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...)


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 this post


Link to post
Share on other sites
Quote:
Original post by TheAdmiral
What 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 this post


Link to post
Share on other sites
Quote:
Original post by nonoptimalrobot

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.



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

Quote:
Original post by nonoptimalrobot

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.



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


Quote:
Original post by nonoptimalrobot

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.



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 this post


Link to post
Share on other sites
Quote:
Original post by Conn

I 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?

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!