- Home /
How do I manage collisions between characters being moved around by their transform.position?
I chose to move my characters around with: transform.position += direction * Time.deltaTime.
This is because I want total control over my characters, (this would be harder with rigidbodies).
The problem is that no obstacle can stop a character being moved by transform.position
But how would I make my character fall or trip over if he gets too close to another character? Would I have to make some advanced script to detect when his feet get to close to another character?
Answer by tanoshimi · Feb 29, 2016 at 08:04 PM
Yes. If you're choosing not to use the physics engine for rigidbody movement, then you need to roll your own collision handling code instead.
Note that you can still use triggers on kinematic rigidbodies that you move yourself to test whether one collider enters another, say, but you won't get detailed information such as collision contact points, so you won't know if the character has tripped or bumped their head... just that some part of them has hit something.
Answer by Placus_Brutus · Mar 01, 2016 at 08:17 AM
On the object that you are moving, create a RayCast in the Update() and check for distance:
RaycastHit objectHit;
float distance = 1.0f; // This is the length of the RayCast
if (Physics.Raycast(transform.position, transform.forward, out objectHit, distance))
{
if (objectHit.collider.tag == "obstacle")
{
Debug.Log("hit an obstacle");
}
}
Your answer
Follow this Question
Related Questions
how to shoot bullets from circumference of a circle ? 1 Answer
Variables modified on other scripts through a Editor Script reset on Play? 1 Answer
SphereCast doesn't work when I increase the radius. 1 Answer
OnPreRender for Handles.DrawCamera 0 Answers
Unity how to access animation states (from blender) with C# ONLY 0 Answers