How do I move the camera sideways in Libgdx?
Posted
by
Bubblewrap
on Game Development
See other posts from Game Development
or by Bubblewrap
Published on 2012-04-02T08:37:43Z
Indexed on
2012/04/02
17:42 UTC
Read the original article
Hit count: 440
I want to move the camera sideways (strafe). I had the following in mind, but it doesn't look like there are standard methods to achieve this in Libgdx.
If I want to move the camera sideways by x, I think I need to do the following:
- Create a Matrix4
mat
- Determine the orthogonal vector v between
camera.direction
andcamera.up
- Translate
mat
byv*x
- Multiply
camera.position
bymat
Will this approach do what I think it does, and is it a good way to do it? And how can I do this in libgdx? I get "stuck" at step 2, as I have not found any standard method in Libgdx to calculate an orthogonal vector.
EDIT: I think I can use camera.direction.crs(camera.up)
to find v
. I'll try this approach tonight and see if it works.
EDIT2: I got it working and didn't need the matrix after all:
Vector3 right = camera.direction.cpy().crs(camera.up).nor();
camera.position.add(right.mul(x));
© Game Development or respective owner