I am trying run my box into a wall (just another box) and have it stop once it collides. I don’t want things to tumble or do anything special - just stop. How do I do this? Rigid-bodies make things go a bit crazy. Any ideas?
Storm
edit: p.s. do I need rigid-bodies to detect collision (other than triggers)? because with just 2 box colliders it isn’t registering any collisions.
UNity Version?
At least in Unity 3 is does appear that you need a rigidbody to make the colliders work. However there are thing you can do to a rigidbody to stop the insanity.
Turn of the Rotation on Collision, and set the drag at 1. This will cause the Effect Velocity to damp at 100% per frame or close to it.
Other wise just use a trigger with a script to set speed to 0 on Enter.
function OnTriggerEnter(Collider: other)
{
...
]
so that answers one question. but here’s another: how should I be doing movement? presently i do:
void Update ()
{
transform.position += (movementspeed * dir) * Time.deltaTime;
if (Input.GetButton ("Horizontal"))
{
dir = transform.right * -Input.GetAxis("Horizontal");
}
else if(Input.GetButton("Vertical"))
{
dir = transform.forward * -Input.GetAxis("Vertical");
}
dir.Normalize();
}
should I be using ApplyForce()? or something similiar instead?
ApplyForce and AddForce are used if you are doing a phsyics based moved, and want movement modelled based on that. These are recommended to happen in the FixedUpdate rather than Update, to provide a consistant physics feel.
You type of movement is fine if you arent looking for phsyic (at least from the player end). There is also a physic Character Controller and a FPS Input Controller and Character Motor scripts included with Unity, that provide player controlled by phsyic type movement.