- Home /
moving in a straight line, but variable speed
So I am moving a car in a straight line but I want it to accelerate up to a maximum speed. I am thinking that animationCurve is a good way to go, but am not exactly sure how to execute this. How would I set up an animationCurve and use it to drive the car's transform?
Expanding a bit:
at t=0 sec, xPosition = 0 at t=1 sec, xPosition = 0.5 at t=2 sec, xPosition = 1.5 at t=3 sec, xPosition = 4.5
... and so on. Was thinking these values for t and xPosition would simply represent the keyFrames in an accelerationCurve. Does this sound right? If so, could anyone throw together some quick code to show me how to do this?
Thanks!
Answer by PrimeDerektive · Feb 23, 2011 at 09:13 PM
Hmm, that sounds like a terrible idea. To accelerate up to a maximum velocity, I would make the car object a rigidbody and do something like this (very basic example):
var accel : float = 3.0; var maxSpeed : float = 30.0;
function FixedUpdate(){ if(rigidbody.velocity.magnitude < maxSpeed) rigidbody.AddForce(Vector3.forward*accel); }
But, if I changed the example to something other than velocity, acceleration etc (thus we did not have the physics engine), would this be an appropriate use of accelerationCurve. I am just trying to understand what its about ... Thanks
Then I would use transform.translate, and do a similar thing (but you'd have to measure velocity yourself). Animation curves are for animated models with animation clips (for instance, a human model with a walk animation or a punch animation). I wouldn't handle actual movement with animations.
Your answer
Follow this Question
Related Questions
Move Player without acceleration 1 Answer
Rigidybody2D addforce at constant speed 1 Answer
How do I make and object move in sync with its animation? 1 Answer
Add acceleration to movement 0 Answers