Setting players basis locks rotation

Godot Version

Godot 4.1 + Voxel Adon

Question

Hello I am trying to create a space game, in this game I set the players transform.basis in order to keep them oriented downwards to the planet. This is working with the following code:

transform.basis.y = (transform.origin - planet.transform.origin).normalized() + mouse_mov
transform.basis.z = transform.basis.y.cross(Vector3(1,0,0)).normalized()
transform.basis.x = transform.basis.y.cross(Vector3(0,0,1))

The problem I have a _unhandled_input function that controls player look. I originally had the Y rotation of the player get changed by the movement of the mouse on the x axis. However after setting the basis on the 3 axises I can no longer rotate the player on the y axis. I have tried the following methods:

transform.basis = transform.basis * Basis(transform.basis.y,-event.relative.x*0.005)
transform = transform * Transform3D(Basis(transform.basis.y,-event.relative.x*0.005),Vector3(0,0,0))
rotation.y += -event.relative.x*0.005
rotate(transform.basis.y,-event.relative.x*0.005)
rotate_object_local(transform.basis.y,-event.relative.x*0.005)
transform.basis = transform.basis.rotated(transform.basis.y,-event.relative.x*0.005)

I assume this has to do with me already setting the basis to something else an so the basis is locked. How ever I can’t really seem to think as to how to integrate the mouse motion into the basis setting. I also need to set the basis so the player can stay on the planet (-y basis is gravity).

Eventually I would also like to have the planet move and the player stay with it without a parent child relationship as I want to be able to move to other planets. I originally thought that doing transform * planet.transform would do it but the player then fails to rotate properly again.

Wouldn’t it be easier to set the rotation of the player instead of the basis?
Also, since you’re using the basis, the rotation is composed into it differently for each axis. When you set x y z to fixed numbers on the basis you’re effectively preventing at least two of the rotations. It’s just not how that is done.

So what exactly would i rotate by. I guess i really dont understand much here. Thought setting the basis would just set the players local realtive directs like up and forward.

You should just really use the rotate method on Node3D or the rotated method on Vector3 and the assign to the rotation property, just don’t touch the basis for anything without a very, very good reason.

Solution:
set the basis.y to towards the planet, set the basis.x to the basis.y crossed with basis.z. Do not set basis.z. movement directions should be rotated by a separate y_pivot node that also controls the camera.

	transform.basis.y = (transform.origin - planet.transform.origin).normalized()
	transform.basis.x = transform.basis.y.cross(transform.basis.z)
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.