- Home /
How to Have a Rigid Body Gain Forward Speed when Dropped?
Hey everybody.
Here's what I'm trying to achieve.
What's the best way to have a rigid body gain forward speed when being dropped from height? So, for example if you just had a cube and dropped it, it would start to move forward, gaining forward speed with a nice smooth transition?
Any ideas?
Thanks in advance.
I don't have Physics in my game but maybe something like rigidbody.AddForce(10, -10, 0);
(from FixedUpdate)
Answer by Prosto_Lyubo · Aug 26, 2013 at 08:54 AM
Add a velocity to it, Lerping it from 0 to Your max value:
private float SmoothConst=0.3f;
private float MaxSpeed=10f;
public Rigidbody MyCube;
void Update{
if (MyCubeIsFallingCondition){
MyCube.velocity = new Vector3(0 ,0 ,Mathf.Lerp(MyCube.velocity.z,MaxSpeed, Time.deltaTime*SmoothConst));
}
}
Note, that if it already is moving it will gain speed beginning with its current speed, othervise it will start from 0 velocity.
Thanks a bunch for your help. This is what I was after.
Your answer
Follow this Question
Related Questions
rigid body problem 1 Answer
Freezing Rigidbody Rotation 1 Answer
Colliding with static model 1 Answer
Enemy AI and Rigid Bodies 0 Answers
Rigid body enemy 1 Answer