- Home /
Can i change position depending on another object axis?
Hi, I'm beginner in unity scripting and i want to know that is there any way to change positions alone depending on the local axis of another object. I have a game object and i want to move it depending on the local axis of the camera. the camera rotates with gyro.
Comment
Answer by robusto · Jun 14, 2014 at 11:12 AM
This is an example:
float step = 20f * Time.deltaTime; // change -20f to move it the opposite way, also controls how big/small the step in that direction is for each call.
Camera camera = Camera.main;
transform.position += camera.transform.right * step; // moves right or left
transform.position += camera.transform.up * step; // moves up or down
transform.position += camera.transform.forward * step; // moves towards or away from camera
i'm rotating camera using Gyro and object remains in same position until you drag it. while dragging object moves in world axis i want to move it in camera's local axis.
Answer by Umresh · Jul 22, 2014 at 01:38 PM
H, i found answer you can use Transform.Translate(object to rotate,object whose axis to refer)
Your answer
