- Home /
Is there a way to make a Character Controller stop instead of move over obstacles??
I'm making a flying camera in a 3rd person game. I want the camera to stop moving when it hits an obstacle. I tried various raycast/spherecast techniques but none of them worked right.
So, I attached a Character Controller to the camera. It works pretty well, but it wants to climb over obstacles. I tried making the Slope Limit 0, but it still climbs over some stuff, or slides against the floor.
Is there any way to make the Character Controller come to a dead stop when it hits something? Perhaps by using the OnControllerColliderHit event/callback?
Answer by Waz · Aug 03, 2011 at 06:33 AM
I've used something like this:
 var stopDead = false;
 function MoveOrStop(dir: Vector3)
 {
     stopDead = false;
     var oldPos = transform.position;
     controller.Move(dir);
     if (stopDead)
         transform.position = oldPos;
 }
 function OnControllerColliderHit (hit : ControllerColliderHit)
 {
     if (hit is something that should stop you)
         stopDead = true;
 }
This works very well--but one problem with it is it stays at the previous position ins$$anonymous$$d of backing the object out to the point of contact. If you move very fast, the previous position isn't very close to what you collided with.
I've not found a decent way to do this. I think I might just re-do the move with smaller and smaller increments until it doesn't collide.
Really wish Unity would just have a stop dead flag on the controller.
Your answer
 
 
             Follow this Question
Related Questions
Character Controller being pushed or not colliding with Plane Collider 0 Answers
add camera collision without CharacterController 1 Answer
Any way to ignore collision between rigidbodies and colliders/character controllers? 1 Answer
Problem with character controller and collisions 1 Answer
Is it possible to hide an object from certain cameras? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                