39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class player : CharacterBody3D
|
|
{
|
|
[Export] public const float Speed = 5.0f;
|
|
[Export] public const float JumpVelocity = 4.5f;
|
|
[Export] public const float gravity = 9f;
|
|
|
|
//eveyrthing will be replaced with roatation and direction based movement
|
|
//camera global position will be included when calculating the player movement
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
Vector3 velocity = Velocity;
|
|
|
|
if (!IsOnFloor())
|
|
velocity.y -= gravity * (float)delta;
|
|
|
|
if (Input.IsActionJustPressed("move_jump") && IsOnFloor())
|
|
velocity.y = JumpVelocity;
|
|
|
|
Vector2 inputDir = Input.GetVector("move_left", "move_right", "move_forward", "move_backward");
|
|
Vector3 direction = (Transform.basis * new Vector3(inputDir.x, 0, inputDir.y)).Normalized();
|
|
if (direction != Vector3.Zero)
|
|
{
|
|
velocity.x = direction.x * Speed;
|
|
velocity.z = direction.z * Speed;
|
|
}
|
|
else
|
|
{
|
|
velocity.x = Mathf.MoveToward(Velocity.x, 0, Speed);
|
|
velocity.z = Mathf.MoveToward(Velocity.z, 0, Speed);
|
|
}
|
|
|
|
Velocity = velocity;
|
|
MoveAndSlide();
|
|
}
|
|
}
|