- Home /
Opposite direction in Trigger Enter
I have so many gameobjects in the scene.
The gameobjects moving by using TRANSLATE function.
transform.Translate(direction * Time.deltaTime * speed);
In trigger enter the objects should move in opposite direction
How can i do it??
Answer by robertbu · Jul 04, 2013 at 05:33 AM
Add a variable at the top of the file. I call it 'forback' for forwards and backwards:
var forback = 1.0;
Then your Translate() becomes:
transform.Translate(forback * direction * Time.deltaTime * speed);
Then to reverse the direction:
function OnTriggerEnter() {
forback = -forback;
Debug.Log("Entered the trigger");
}
Your character will need a Rigidbody to make this work.
I don't understand "another conditions." Do you need to open a new question or is there an issue here?
Your answer
Follow this Question
Related Questions
Transform.Translate() coordinates confusion 2 Answers
Follow another object direction problem 1 Answer
C# Smoothing Out transform.Translate 4 Answers
Vector3 Returning Infinity Error 2 Answers
Transform continue direction 0 Answers