I want when my character touches the plane which I call “Floor” it teleport the player back to the start which is (0, 3, 40); You know floor is lava. This my code:
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.gameObject.name == "Floor")
{
transform.position = new Vector3(0, 3, 40);
}
Rigidbody body = hit.collider.attachedRigidbody;
//dont move the rigidbody if the character is on top of it
if (m_CollisionFlags == CollisionFlags.Below)
{
return;
}
if (body == null || body.isKinematic)
{
return;
}
body.AddForceAtPosition(m_CharacterController.velocity * 0.1f, hit.point, ForceMode.Impulse);
}
When you replace the teleportation code with a debug.log code it notices that the player is on the plane
if (hit.gameObject.name == "Floor")
{
Debug.Log("TouchingFloor");
}
Its wierd…