Moving an object sideways using something similar to camera.getForwardRay()

I’m currently doing something like

var direction = camera.getForwardRay().direction;
hero.position.x += direction.x * 10;
hero.position.y += direction.y * 10;
hero.position.z += direction.z * 10;

and it works the way I like it; move towards where the camera is facing, but how can I move it sideways relative to where the camera is facing?

1 Like

I guess you could do a cross product between the direction and the camera up vector to find the side one.


You can use getDirection with (1,0,0) as the local axis. (0,1,0) is local up and (0,0,1) is lcoal forward


Thank you, worked like a charm

1 Like