rb.AddForce(transform.forward*thrust,ForceMode.Impulse);
2 Answers
2Increase the Drag value in the Rigidbody Component of the GameObject
hey @harshit sharma
I needed to get this thing in past what you’re trying to achieve right now. I did it like this.
You need to increase a drag of rigid body in order to slow it down and finally stop it. so Call a coroutine right after you add force to rigid body.
Here is some code:
void ForceToRigidBody(){
rb.AddForce(transform.forward*thrust,ForceMode.Impulse);
StartCoroutine(AddDrag());
}
IEnumerator AddDrag(){
float current_drag = 0;
while(current_drag < maxDrag){
current_drag += Time.deltaTime * mul;
rb.drag = current_drag;
yield return null;
}
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
rb.drag = 0;
}
Tweak these values of maximum drag and multiplayer as you see fit.
Problem solved!!! You are super! Thanks a million!!!
– tammyhuang