c# - Unity 5 object collision not detecting -
so i've started using unity , new c#.
i'm running problem sphere (player) wont detect collision touches other objects (runs right through).
i wanted have player move units units corresponding left, right, up, down keyboard inputs instead of physics.
heres code:
public float distance; void fixedupdate(){ if (input.getbuttondown("horizontal") && input.getaxisraw("horizontal") > 0) { transform.translate (distance, 0.0f, 0); } else if (input.getbuttondown("horizontal") && input.getaxisraw("horizontal") < 0) { transform.translate (-distance, 0.0f, 0); } else if (input.getbuttondown("vertical") && input.getaxisraw("vertical") > 0) { transform.translate(0, 0, distance); }else if(input.getbuttondown("vertical") && input.getaxisraw("vertical") < 0){ transform.translate(0, 0, -distance); } }
to detect collisions, not need collider component, rigidbody component well. other objects need detect collisions need either rigidbody or static colliders. also, it's safer use rigidbody.moveposition
or rigidbody.addforce
instead of transform methods.
Comments
Post a Comment