Initial commit
This commit is contained in:
commit
1d7fa4e5c9
18 changed files with 785 additions and 0 deletions
52
scripts/Player.cs
Normal file
52
scripts/Player.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace MinImm;
|
||||
|
||||
public partial class Player : CharacterBody3D
|
||||
{
|
||||
[Export] public Camera3D Camera { get; set; }
|
||||
[Export] public float Speed { get; set; } = 5f;
|
||||
[Export] public float Gravity { get; set; } = 20f;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Input.SetMouseMode(Input.MouseModeEnum.Captured);
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseMotion mouseMotion)
|
||||
{
|
||||
RotationDegrees = RotationDegrees with { Y = RotationDegrees.Y - mouseMotion.ScreenRelative.X * 0.5f };
|
||||
Camera.RotationDegrees = Camera.RotationDegrees with
|
||||
{
|
||||
X = Math.Clamp(Camera.RotationDegrees.X - mouseMotion.ScreenRelative.Y * 0.2f, -60, 60)
|
||||
};
|
||||
}
|
||||
else if (@event.IsActionPressed("ui_cancel"))
|
||||
{
|
||||
Input.SetMouseMode(Input.MouseModeEnum.Visible);
|
||||
}
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var inputDirection = Input.GetVector("move_left", "move_right", "move_forward", "move_backward");
|
||||
var input3D = new Vector3(inputDirection.X, 0, inputDirection.Y);
|
||||
var direction = Transform.Basis * input3D;
|
||||
|
||||
var velY = (float)(Velocity.Y - Gravity * delta);
|
||||
if (Input.IsActionJustPressed("jump") && IsOnFloor())
|
||||
{
|
||||
velY = 10f;
|
||||
}
|
||||
else if (Input.IsActionJustReleased("jump") && velY > 0)
|
||||
{
|
||||
velY = 0f;
|
||||
}
|
||||
|
||||
Velocity = Velocity with { X = direction.X * Speed, Y = velY, Z = direction.Z * Speed };
|
||||
MoveAndSlide();
|
||||
}
|
||||
}
|
||||
1
scripts/Player.cs.uid
Normal file
1
scripts/Player.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c1ojbknjgowvd
|
||||
Loading…
Add table
Add a link
Reference in a new issue