4 Replies Latest reply on Jul 18, 2010 4:21 PM by 843799

# Creating realistic motion

Does anyone know of a way of creating the realistic motion of an object? Say I have a sphere in my scene and I apply a positionInterpolator to it so that it rises and falls is there any way I can make it decellerate and accelerate according to the law gravity as it would naturally?

If it were possible to apply different increasing alpha ramp durations to the Alpha object it may be possible, but this is not the case.

Any suggestions would be much appreciated,

Nik
• ###### 1. Re: Creating realistic motion

Use a TransformInterpolator and override the computeTransform() method with something that resembles real world physics. For example:

class MyInterp extends TransformInterpolator {

public void computeTransform(float alphaValue, Transform3D transform)
{
//Perform physics based math to input alpha
float interpVal = physicsMath(alphaValue);

transform.set(axis);
transform.scale(interpVal);
}

private float physicsMath(float val)
{
//Standard cubic function on [0 1]
return ((-2f * val) + 3) * val * val;
}
}

The above interpolator should (I've not debugged it) start with your object at rest, accelerate it to it's top speed when alpha is at .5, and slow it to a stop again at alpha = 1. The key here is to override physicsMath() with whatever physics function best represents the behaviour you want to model. It helps to think that the alpha will change at a constant rate from 0 to 1 and that your math must mould this into something with the slow downs and speed ups you need.

You could also avoid Alphas all together and implement animation in a seperate thread. That's what I do.

Mark McKay
--
http://www.kitfox.com
• ###### 2. Re: Creating realistic motion
Thank you very much Mark, you were spot on.