cleaned up project

This commit is contained in:
2023-01-03 19:04:11 +01:00
parent 0234bf3fc8
commit f1cbea5b8a
8 changed files with 19 additions and 145 deletions

View File

@@ -1,17 +1,17 @@
using Godot;
using System;
public partial class player : CharacterBody3D
{
[Export] float Speed = 5.0f;
[Export] float JumpVelocity = 5f;
[Export] float speed = 5.0f;
[Export] float jumpVelocity = 5f;
[Export] float gravity = 14f;
[Export(PropertyHint.Range, "0.1,1.0")] float mouseSensitivity = 0.3f;
[Export(PropertyHint.Range, "-90,0,1")] float minMousePitch = -90f;
[Export(PropertyHint.Range, "0,90,1")] float maxMousePitch = 50f;
[Export(PropertyHint.Range, "0,90,1")] float maxMousePitch = 90f;
public override void _Process(double delta)
{
//uncapturing the mouse disables player movement but still simulates gravity
if (Input.IsActionJustPressed("uncapture_mouse")) Input.MouseMode = Input.MouseModeEnum.Visible;
if (Input.IsMouseButtonPressed(MouseButton.Left)) Input.MouseMode = Input.MouseModeEnum.Captured;
}
@@ -20,25 +20,26 @@ public partial class player : CharacterBody3D
Vector3 velocity = Velocity;
if (!IsOnFloor())
velocity.y -= gravity * (float)delta;
velocity.y -= gravity * (float)delta; //characterbodys don't have physic simulations by default like rigidbody
if (Input.IsActionJustPressed("move_jump") && IsOnFloor() && Input.MouseMode == Input.MouseModeEnum.Captured)
velocity.y = JumpVelocity;
velocity.y = jumpVelocity;
Vector2 inputDir = Input.GetVector("move_left", "move_right", "move_forward", "move_backward");
Vector3 direction = new Vector3(inputDir.x, 0, inputDir.y).Rotated(Vector3.Up, GetNode<Marker3D>("camera_center").Rotation.y).Normalized();
Vector3 direction = new Vector3(inputDir.x, 0, inputDir.y).Rotated(Vector3.Up, GetNode<Marker3D>("camera_center").Rotation.y).Normalized(); //rotates the input direction with camera rotation
if (direction != Vector3.Zero)
{
velocity.x = direction.x * Speed;
velocity.z = direction.z * Speed;
velocity.x = direction.x * speed;
velocity.z = direction.z * speed;
//Rotating the body mesh to movement
Vector3 bodyRotation = GetNode<MeshInstance3D>("collision/body").Rotation;
bodyRotation.y = Mathf.LerpAngle(bodyRotation.y,Mathf.Atan2(-direction.x, -direction.z), (float)delta * Speed);
bodyRotation.y = Mathf.LerpAngle(bodyRotation.y,Mathf.Atan2(-direction.x, -direction.z), (float)delta * speed);
GetNode<MeshInstance3D>("collision/body").Rotation = bodyRotation;
}
else
{
velocity.x = Mathf.MoveToward(Velocity.x, 0, Speed);
velocity.z = Mathf.MoveToward(Velocity.z, 0, Speed);
velocity.x = Mathf.MoveToward(Velocity.x, 0, speed);
velocity.z = Mathf.MoveToward(Velocity.z, 0, speed);
}
Velocity = velocity;
MoveAndSlide();
@@ -50,7 +51,7 @@ public partial class player : CharacterBody3D
Vector3 camRot = GetNode<Marker3D>("camera_center").RotationDegrees;
camRot.y -= mouseMotion.Relative.x * mouseSensitivity;
camRot.x -= mouseMotion.Relative.y * mouseSensitivity;
camRot.x = Mathf.Clamp(camRot.x, minMousePitch, maxMousePitch);
camRot.x = Mathf.Clamp(camRot.x, minMousePitch, maxMousePitch); //prevents camera from going endlessly around the player
GetNode<Marker3D>("camera_center").RotationDegrees = camRot;
}
}

View File

@@ -1,7 +1,7 @@
using Godot;
using System;
public partial class essential : Node
public partial class window : Node
{
public override void _Ready()
{