I made an attempt at controlling the orientation of a ship in space in 3d according to the relative mouse motion. The camera is attached to the ship, so parts of the ship appear fixed, and the background panorama sky (star background) seems to move.
The motion I achieve is really jumpy - instead of moving smoothly, each relative change of the mouse causes a largish change in the movement of the stars.
How can I make this smoother?
I didn't post queryMouseMoveEvent - it just checks if the relative mouse motion would cause the motion being passed in. And the hard coded numbers 1 and 0 represent the x axis and the z axis.
var lastMousePosition = Vector2(0,0)
if event is InputEventMouseMotion:
lastMousePosition = event.relative
ship.rotateShip(1, deg2rad(lastMousePosition.x), false, MouseSensitivity, delta)
ship.rotateShip(1, deg2rad(lastMousePosition.x), true, MouseSensitivity, delta)
ship.rotateShip(0, deg2rad(lastMousePosition.y), true, MouseSensitivity, delta)
ship.rotateShip(0, deg2rad(lastMousePosition.y), false, MouseSensitivity, delta)
lastMousePosition = Vector2(0,0)
And finally, inside the ship script:
func rotateShip(axis, radians, negate, sensitivity, delta):
var basis = self.transform.basis
var amount = sensitivity
amount = -amount
var xaxis = basis.x
var yaxis = basis.y
var zaxis = basis.z
var deltaAmount = amount * delta
# select axis
chosenAxis = xaxis
chosenAxis = yaxis
chosenAxis = zaxis