c# - Cube seems to go in reverse direction as in script in Unity3D -
i have cube , main camera child. have attached script on cube following statement in update():
transform.translate(vector3.normalize(camera.main.transform.forward) * speed); speed=0 , increases every frame.
this should move cube in forward direction of camera facing. works fine when initial rotation of both cube , camera (0,0,0) , (0,0,0) respectively. works fine if camera rotates (0,180,0) keeping cube @ (0,0,0) rotation. if cube rotated (0,180,0), cube , hence camera moves in reverse direction.
i tried this:
transform.translate(vector3.movetowards(transform.position, camera.main.transform.forward, speed)); but same results.
if don't specify explicitely, translation assumed relative object space. here yo u want move cube using camera direction in world space. try following:
transform.translate(camera.main.transform.forward * speed, space.world);
Comments
Post a Comment