- Home /
OnCollisionEnter Does NOT work for the player - But works flawlessly for other GameObjects
Hi all, Im trying to make a simple script that moves Objects and the Player to a 'respawn' location if they happen to fall through the map, this works flawlessly for GameObjects, but wont recognize the Player what so ever, I ended up adding a OnCollisionStay & OnCollisionExit to try see what was going on, but It doesnt seem to recognize the player at all, The play can just walk around on the Collider but doesnt trigger any events. Obviously I'm doing something wrong, I just can't figure it out. My guess is that Character Colliders dont work the same way Box/Sphere ect Colliders work, is there something I can add to my code that will also work for CharacterColliders?
Video: https://www.youtube.com/watch?v=tBunbBySgcU
Player:
GameObjects:
Code:
using UnityEngine;
public class lostItemReturn : MonoBehaviour
{
[SerializeField] Transform returnTele;
void OnControllerColliderHit(ControllerColliderHit hit) => TeleportBack(hit.transform);
void OnCollisionEnter(Collision other) => TeleportBack(other.transform);
void TeleportBack(Transform trans)
{
Rigidbody rig = trans.gameObject.GetComponent<Rigidbody>();
rig.isKinematic = true;
trans.position = returnTele.position;
trans.Rotate(0, 0, 0);
rig.isKinematic = false;
}
}
Sorry for the late reply, I dont get any notifications from comments, I will try change this in my settings
Its just a Unity Standard Assets FPC with a pause script on it, I highly doubt that its because it's on discrete as the GameObjects are set as discrete aswell.
i cant see the picture sorry, the fpc has kinematic enabled? i think kinematic gameobjects dont fire collision events, if so, can you add a rigidbody to the box that is suppost to have the collision? with is kinematic and use gravity both disable
Your answer
Follow this Question
Related Questions
Make characters go through each other 1 Answer
Destroy character when collision with enemy 3 Answers
Character doesen't collide 3 Answers
Multiple colliders (triggers) in same script? 1 Answer
Moving a player on a rigidbody platform that can collide 2 Answers