Hi, I'm trying to figure out how to make a player face the direction a camera is looking when pressing "move_forward". The camera attached to a SpringArm3D which is a child of Player.
This is my code so far
private void RotatePlayerToCamera()
{
// 1) Freeze this camera so it ignores the player's transform:
TopLevel = true;
// 2) Read this camera’s world‐space yaw & pitch:
Vector3 camGlobalEuler = SpringArm.GlobalTransform.Basis.GetEuler();
float globalCamPitch = camGlobalEuler.X;
float globalCamYaw = camGlobalEuler.Y;
GD.Print($"camPitch = {globalCamPitch}");
GD.Print($"camYaw = {globalCamYaw}");
Vector3 camRelativeEuler = SpringArm.Transform.Basis.GetEuler();
float relativeCamPitch = camRelativeEuler.X;
// 3) Snap the player’s Y‐rotation to match the camera’s world‐space yaw:
Vector3 playerRot = Player.Rotation;
playerRot.Y = globalCamYaw;
GD.Print(Player.Rotation);
Player.Rotation = playerRot;
GD.Print(Player.Rotation);
// 4) Force this camera’s local rotation: keep pitch, zero out yaw
Rotation = new Vector3(globalCamPitch, 0f, 0f);
// 7) Unfreeze the camera so it again follows the player:
TopLevel = false;
Position = StationaryPosition.Position;
}
The problem is that it spins like crazy and inverts the camera at some point so moving my mouse right will move it one way, then move the other way somehow
