- Home /
Moving Objects along a vertices
I'm trying to get a cube to move along the z axis like a sliding door when activated by a trigger. At first I was thinking about doing it by having a "Do" loop in the OnTriggerEnter function, however it just crashed Unity. Please could someone help me out here, there's probably a simple way of doing this however I'm stumped for the moment.
Thanks!
Answer by Lovrenc · Jan 12, 2013 at 12:44 AM
OnTriggerEnter happend when something triggers your collider. You cant use do/while loop to do animation in there. It represents one frame. Easiest way:
Have a variable that says wheather door should open or close;
bool isOpening = false;
bool stateOpen = false;
When user collides, save the state. Door is now oppening!
void OnCollisionEnter(Collision collision) {
isOpening = true;
}
In update function of door you do this:
void Update() {
if(isOpening && !stateOpen) {
//insert your movement vector * Time.deltaTime.
}
}
Your answer
Follow this Question
Related Questions
I am trying to make a movement script for my main camera but it isnt working! 2 Answers
Issues with C# script (using tutorial) 1 Answer
Adding simple strafing to my character controller script... 0 Answers
Moving an animated object's animator instead of the object? 0 Answers
Position of all spawned prefabs being effected by MoveTowards (beginner question) 1 Answer