movement now adjusts with camera angle (it was too easy)
This commit is contained in:
@@ -12,6 +12,8 @@ public partial class player : CharacterBody3D
|
|||||||
public float allDelta;
|
public float allDelta;
|
||||||
public Marker3D camCenter;
|
public Marker3D camCenter;
|
||||||
|
|
||||||
|
//eveyrthing will be replaced with roatation and direction based movement
|
||||||
|
//camera global position will be included when calculating the player movement
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
camCenter = GetNode<Marker3D>("camera_center");
|
camCenter = GetNode<Marker3D>("camera_center");
|
||||||
@@ -26,9 +28,9 @@ public partial class player : CharacterBody3D
|
|||||||
|
|
||||||
if (Input.IsActionJustPressed("move_jump") && IsOnFloor())
|
if (Input.IsActionJustPressed("move_jump") && IsOnFloor())
|
||||||
velocity.y = JumpVelocity;
|
velocity.y = JumpVelocity;
|
||||||
Vector2 camRotVector = new Vector2 ((float)Math.Cos(camCenter.Rotation.y), (float)Math.Sin(camCenter.Rotation.y));
|
|
||||||
Vector2 inputDir = Input.GetVector("move_left", "move_right", "move_forward", "move_backward") * camRotVector;
|
Vector2 inputDir = Input.GetVector("move_left", "move_right", "move_forward", "move_backward");
|
||||||
Vector3 direction = new Vector3(inputDir.x * camRotVector.x, 0, inputDir.y * camRotVector.y);
|
Vector3 direction = (camCenter.Transform.basis * new Vector3(inputDir.x, 0, inputDir.y)).Normalized();
|
||||||
if (direction != Vector3.Zero)
|
if (direction != Vector3.Zero)
|
||||||
{
|
{
|
||||||
velocity.x = direction.x * Speed;
|
velocity.x = direction.x * Speed;
|
||||||
|
Reference in New Issue
Block a user