- Home /
Question by
Machineman1357 · Mar 23, 2013 at 05:06 AM ·
2dtransformpositionnewbie
How to change a moving box's direction once it hits a point?
In the attached file I have a picture showing a red box and a blue box. The red box will be moving down until it reaches the the blue box's horizontal coordinates. The question I have is: how do I change the direction it is going to be going once it hits that position? I have tried:
//this script is on the red box
function Update () {
transform.Translate(0, 0, -5 * Time.deltaTime);
var myPosition = transform.position;
if(myPosition == Vector3(10, 3, 0)) {
transform.Translate(-5 * Time.deltaTime, 0, 0);
}
}
This may be obvious to you, but I am very fresh off of the boat on scripting so any help would be kindly taken.
Thank you.
untitled-1.jpg
(7.8 kB)
Comment