- Home /
Too many questions with no selected (Ticked) answer.
2 cubes go through each other instead of stopping
I have one cube that moves and one cube that stays still. They both have box colliders and rigidbodys, but they still go through each other. I want them to stop when they bump into each other.
Thanks!
There are several reasons for that two happen:
you are moving the cubes using transform.position ins$$anonymous$$d of Rigibody.AddForce
your cubes have their layermasks set up so that they ignore collisions between them.
c#:
float amtTo$$anonymous$$ove = Input.GetAxis("Horizontal") * playerSpeed;
transform.Translate(Vector3.right*amtTo$$anonymous$$ove*Time.deltaTime );
float amtTo$$anonymous$$ove2 = Input.GetAxis("Vertical") * playerSpeed;
transform.Translate(Vector3.up*amtTo$$anonymous$$ove2*Time.deltaTime );
How can I make this "Rigidbody.AddForce"?
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html
You would replace your transform.Translate with transform.rigidbody.AddForce.
Oh also. Please go back to your old questions and accept the right answers. I just had a quick look at your profile and saw you had only one closed questions and that one was closed by a moderator/high-karma user. If your question on UA is solved you should always accept the right answer so that the question gets marked as solved. This way no one will try to answer already answered questions.
Now the Cube won't move at all. Here is my script: c#:
float amtTo$$anonymous$$ove = Input.GetAxis("Horizontal") * playerSpeed;
transform.rigidbody.AddForce(Vector3.right*amtTo$$anonymous$$ove*Time.deltaTime );
float amtTo$$anonymous$$ove2 = Input.GetAxis("Vertical") * playerSpeed;
transform.rigidbody.AddForce(Vector3.up*amtTo$$anonymous$$ove2*Time.deltaTime );
Follow this Question
Related Questions
3D box collider go through terrain 1 Answer
Adding a spring or joint makes object fall through object 0 Answers
Collider going through walls with box collider.. 1 Answer
Rigidbodys 0 Answers
Transform.position with Box Collider? 4 Answers