- Home /
Car physics like cartoon cars
Hi guys,Please help me I'm making a multiplayer cartoon (low poly) type 3d car game where all cars fights with each other. For that, I need my car physics like turning quickly and dodging bullets. I don't want to use wheel colliders (I don't need real car physics) I tried finding on the everywhere but can't find the physics I really need. How can I achieve this physics?
Car physics exactly like this game : https://play.google.com/store/apps/details?id=com.notdoppler.crashofcars&hl=en
Try use rigidbody and make it like a character movement. Rotation and position etc.
Answer by OSharp · Nov 12, 2017 at 05:40 PM
Here is a script I have been working on - It doesn't require any wheels so just make a cube with rigidbody. It has basic drifting and is simplistic (and seriously needs some working on!) but I quite like it as I have just started public float movementSpeed; public float turnSpeed; public float drift; void Start() { GetComponent<Rigidbody>().centerOfMass = new Vector3(0, -3, 0); } void Update() { transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime * drift * -1, 0f, Input.GetAxis("Vertical") * Time.deltaTime * movementSpeed); if (Input.GetKey(KeyCode.A)) { transform.Rotate(0, turnSpeed*-1, 0); } if (Input.GetKey(KeyCode.D)) { transform.Rotate(0, turnSpeed, 0); } if (Input.GetKey(KeyCode.W)) { drift = 30; } else { drift = 0; } }
Thanks for the answer! I managed to do some tweaks to the wheel colliders just for moving and rotating the car so it looks a little realistic and more cartoonistic at the same time but still needs to be perfect. So I tried your code and its closer to how I actually wanted!! I also wanted to drift the car and now I'll be able to do it. Thanks to you!
Answer by IndievdB · Sep 18, 2017 at 07:13 AM
This seems very do-able. All you need is some kind of simple collider(s) covering most of the car, a script for movement, and a RigidBody for physics. The RigidBody, with a bit of tweaking will give you the momentum and feel of that game pretty easily.
Your movement script should add force or somehow alter the velocity of your car. When the player clicks forward, add force to the RigidBody in the direction the car is facing. When the player clicks left/right, slightly rotate the car in that direction. Something like this can act as a template:
void Update()
{
float newRotation = transform.localEulerAngles.y + Input.GetAxis("Horizontal");
transform.localEulerAngles = new Vector3 (0f,newRotation, 0f);
Vector3 input = (transform.forward * Input.GetAxis("Vertical"));
rigidBody.AddForce (input* Time.deltaTime * 10, ForceMode.Impulse);
}
Thanks man, I think I'm getting there but sometimes I find my car floating in air! I can't Freeze Y position because I have some features when I want to add force car in the air.
If the car's RigidBody has gravity enabled, it should fall. If there is a ground below it which also has a RigidBody (with gravity disabled), it should catch it. If they both have a collider. Side-note, RigidBody's can also have Physics $$anonymous$$aterials that adjust their friction and bounciness. Let me know if there are still problems.
Ground has no Rigidbody but $$anonymous$$esh collider, car's Rigidbody has gravity enabled and is$$anonymous$$inematic disabled with a box collider around it. When car collide with a wall or something, it starts floating and then comes down slowly on the floor. I set the mass to 2000. With your code, I'm able to control car movement like I need but still I think it still needs more physics work. Can you give me more info on making it stable? Thanks!
Your answer
Follow this Question
Related Questions
Similar movement to a game (look description) 1 Answer
How do you make an wire/rope type object and attach to 2 separate objects 1 Answer
How to apply frictional Torque 2 Answers
Physics.overlapSphere doesnt detect colliders,Physics.CheckSphere doesn't detect colliders 1 Answer
Problem is not Bouncing 0 Answers