In Runner Game I need to detected collions with Objects. I use CharacterController and OnControllerColliderHit(ControllerColliderHit hit):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mainPlayerScript : MonoBehaviour
{
void OnControllerColliderHit(ControllerColliderHit hit)
{
print(hit.gameObject.name);
}
}
But, if my character collide with some object in front of it - no collision detected! What'd the problem?
P.s. In the game I use the method: my Character always stay. All world moves around it. Is it the best way?
CodePudding user response:
This is because you moved transform.position
. use CharacterController.Move()
instead.
Controller.Move(SomeMotion * Time.deltaTime);
CodePudding user response:
The onControllerColliderHit
only gets called if the controller collides with something while moving using the Charactercontroller.Move()
function. Since your character never moves this won't be called.
If you still want the world to move you could try and use a raycast with set max distance to check if something is in front of your player.