# 3D movement and rotation

To show my issue I used the 3d-tile-based-city-builder example.
Rotation and angle movement already exists in it, now I want to add X and Y movement.

It only works as long as the view is not rotated.
If I rotate the camara e.g. 90 degrees to the left, the previous Left is now in front of me, the Left button press will move me forward instead to the left.
How can it be calculated that the movemant works correctly regardless of the rotation?

This is really a 2D issue in a 3D space. Youâ€™re effectively looking at a GD scene; left/right is along the x axis and up/down along the y axis.

Press left, and the position change is purely along the x axis - the x position changes by an amount, and nothing changes on the y axis.

Now rotate the scene, say by 30 degrees. Left and right is no longer along one axis - itâ€™s shared between x & y. And itâ€™s not shared evenly; thereâ€™s a larger position change along the x axis than the y axis in this case. And as the angle approaches 90 degrees, the positional change along the x axis reduces, while the positional change along the y axis increases.

At 90 degrees, left/right is along the y axis.

Iâ€™ve found the best way to calculate the positional change along each axis is to use trigonometry - the sine and cosine functions. Something along the lines of `x_pos += cos(camera_angle)*80*TimeDelta()` and `y_pos += sin(camera_angle)*80*TimeDelta()`

However, in my brief playing with GD 3D Iâ€™ve found applying an instant force at `camera_angle + 90` degrees a lot easier and simpler.

1 Like

Itâ€™s probably easier to do with mouse controls as it â€śmovesâ€ť with the camera.
I guess, you could try this extension:
https://wiki.gdevelop.io/gdevelop5/extensions/drag-camera-with-pointer/

2 Likes

That would be cool, but how can I combine it with rotation and angle?
I get weird behavior with this.

The events seem fine. What does it do?

Without drag
01

With drag cam extension
02
When I release the middle mouse button it jumps back and the rotation center is different. (I didnâ€™t use camara boundaries in this project.)

With Draggable behavior on a large 3D object
03
Without lerp it reacts far too quickly to a mouse movement. With lerp itâ€™s too slow, if I increase it above 1.8 it flickers and jumps around wildly. Drag objects is only available with the left mouse button. Arrow key movement no longer works.

Maybe I should wait for a proper city-builder 3D camera object behavior extension where simply offers the known functionality from Anno, Cities Skylines etc. maybe with a light slide,â€¦