- Home /
How to stop a 3d object
How to stop a 3D object(say a car) falling downwards when collided with another 3d object(say a road). I have tried this the whole day but no results.
$$anonymous$$oving objects need a rigidbody, and one or more colliders that approximate its shape. Static objects (things that won't move, like the ground or the road) only need a collider (and it's better if you mark the whole game object static). With this setup, collisions work normally.
One thing that you need to be aware of is you can't use BoxColliders on planes with 0 height, it just doesn't work. You either have to use a $$anonymous$$eshCollider or give the BoxCollider a non-zero size (preferably at least 1 unit).
Are the colliders on the objects both mesh colliders? Two mesh colliders won't collide unless one is marked as convex.
Answer by swanne · Jul 03, 2018 at 09:47 AM
Unity Physics will control this for you. All you need to do is make sure that a rigidbody component and collider component are present on the car. Make sure that the collider is not set to trigger. Then also add a collider to the road gameObject, making sure that it is not a trigger.
It's always good practice to Proof of Concept things you're not too sure about. Create a new 3D object of plane and add a collider to it, if one does not aready exist. Then create a 3D object of cube and place it above the plane. Add a collider component to it and a rigidbody component. Press play and watch the cube fall onto the road.
The car is made up of so many things line tires,body,etc. The road is made up of grass(top plane) and mud (bottom plane). All the components of car and road are placed under two game objects named CAR and ROAD . I placed Rigidbody with gravity for the car with a box collider and IsTrigger is unchecked. Also Road have RigidBody with no gravity , added Box Collider with IsTrigger unchecked. But it is not working.
I have created a test scene as you suggested and it works perfectly. But it is not working with the car and the road.
Do any of the other components of the car have colliders or is it just the parent object of CAR which has a collider? Same questions for the 2 layers in the ROAD object. Also, the road doesnt need a RigidBody on it. If you are able to zip your project up and send it to me, i'll be happy to have a look for you.
Answer by MPHYS · Jul 03, 2018 at 10:05 PM
If you want it to simply freeze on the spot try destroying the Rigidbody.
Destroy(youGameObject.GetComponent<Rigidbody>());
Your answer