- Home /
Script on moving object doesn't work?
Hello all,
I ran into a problem that I can't seem to find a solution to... I would appreciate it greatly if anybody could help me out with this one. In my scene, I have a Player and and Object called "Monster." The "Monster" object is moving in a loop on a simple keyframe animation (he is running around.) I have a cube set to "Is Trigger" childed to the Monster that is supposed to load the next level when the player touched it. Here is the script:
using UnityEngine;
using System.Collections;
public class LoadLevel9 : MonoBehaviour
{
void OnTriggerEnter(Collider other){
AutoFade.LoadLevel("BasementEND" ,0,1,Color.black);
}
}
I know for a fact that this script works because I have tested it when it is stationary. It seems almost as if the script does not work because it is moving. Can anybody help me find a solution to this problem? If you need more information, I'm happy to answer any questions. I appreciate your help.
Answer by aldonaletto · Nov 12, 2013 at 04:05 AM
I think you're right: a moving trigger must have a kinematic rigidbody in order to generate OnTrigger events. As a rule of thumb, collision/trigger events only occur when a rigidbody hits a collider, not the other way around. Add a kinematic rigidbody to the cube and your problem probably will be solved.
Also, if you're still having problems after doing what aldonaletto said, it could be that your movements are too fast to register as a hit. If that's the case, your scene scale, collider size and physics accuracy could need some tweaking.
Your answer
Follow this Question
Related Questions
Why does my climb stairs animation not play? 1 Answer
Play parent animation without affecting the child animation 1 Answer
Trigger door animation with external trigger 1 Answer
Getting My FPS Controller To Play An Animation After A Trigger Event 1 Answer
Can a Trigger be triggered by an animated object (script)? 1 Answer