- Home /
move box forward
Hey, i like to move my box while pushing. But the code is not working.
function OnCollisionEnter(collision : Collision) {
if(collision.gameObject.tag == "man"){
Debug.Log("hit2");
transform.position = Vector3(464.8797,1.678224,1.839526);
}
}
Stijn
For starters, that code is very weird. Why are you changing the position to some very specific Vector3? What do you hope to achieve with that?
Otherwise, this is just another '$$anonymous$$y thing doesn't collide with this other thing' question, similar to about 1000 other question on this site. Please use the search bar before posting.
Here are some sample posts to get you started:
http://answers.unity3d.com/questions/192271/collision-problem.html
http://answers.unity3d.com/questions/223213/simple-collision-code-problems.html
http://answers.unity3d.com/questions/17828/problem-with-collision-detection.html
http://answers.unity3d.com/questions/150859/collision-problem-with-fpc.html
http://answers.unity3d.com/questions/217686/why-to-collision-detectio-isnt-working-.html
Wow, ok. That is the first fail i've seen in like 5 $$anonymous$$utes. @syclamoth
What he is trying to accomplish is unnecessary.
1.) Click on the object that needs moved.
2.) Go to Component.
3.) Go to Physics.
4.) Add a rigidbody.
5.) Do that to your character/thing-that-is-touching-the-box.
Why create physics when you already have them?
Answer by Chimera3D · May 11, 2012 at 05:06 PM
Just use transform.Translate or use a rigidbody which allows for really nice physics. Just set the object's mass to like .5 or something. Really, USE THE SEARCHBAR to find things that have already been asked and answered before. This is really simple.