Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

How to set rigidbody velocity and angularVelocity to Vector3.zero over time?

$
0
0
Hey! I'm currently working on a vehicle system for my game, and when you accelerate, the vehicle's rigidbody adds a thrust force, but when you hit 'S' to brake, it stops inmediatly (I'm setting velocity and angularVelocity to zero) Here's the code: if (carReverse == false) { if (Input.GetKey (KeyCode.W) && carCurrentSpeed <= carMaxSpeed) { vehRb.AddForce (Vector3.forward * carThrust); } else if (Input.GetKey (KeyCode.W) == false && Input.GetKey (KeyCode.S) == false && carCurrentSpeed >= 0.03f) { vehRb.AddForce (Vector3.forward * -carThrust); } else if (Input.GetKey (KeyCode.W) == false && Input.GetKey (KeyCode.S) && carCurrentSpeed >= 1f) { vehRb.velocity = Vector3.zero * Time.deltaTime; vehRb.angularVelocity = Vector3.zero * Time.deltaTime; } } I tried putting 'Time.deltaTime' to see if it would stop as time passed but it instantly stops the vehicle, and by the way this isn't the classic W to drive forward and S to drive backwards, this thing I'm trying to do is to hit 'W' to increase speed either forward or backwards depending if 'carReverse' is true or false, and the S key is only to stop. Thanks in advance.

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>