- Home /
Moving an object in camera direction?
I have a camera that rotates around an object and I want the object to move forward as to where the camera is looking. Can't really think of a way to do it, any tips?
Answer by DaveA · Mar 22, 2011 at 10:17 PM
Camera.main.transform.forward is where it's looking. You could translate your object along the negative of that, or move the camera forward.
No idea how to use this at all. It outputs something from 0 to 1 and I have no idea how to move my object in that...
That's 'normalized' direction. If you multiply that vector by a number (where 1 = 1 meter), it will give you that distance in that direction.
Actually for you, you might want to subtract the object's transform.postion from the Camera.main.transform.position, then normalize that, to get the direction from the object's origin to the camera. Then multiply that normalized vector by the amount you want to use and add that vector back to the object's transform.position (or call transform.Translate())
This gives me forward in rotation and position which breaks stuff and makes forward not forward and whatnot. If I try transform.position.forward, it complains about some not access stuff.
Using this camera view angle seems to affect the move speed because it also takes rotation into consideration.