Translated Player Scripts from GDScript to C#

This commit is contained in:
2025-03-27 23:12:16 +01:00
parent d4b7c0bf45
commit 7f8b444270
5 changed files with 54 additions and 4 deletions
+20
View File
@@ -0,0 +1,20 @@
using Godot;
namespace Babushka.scripts.CSharp.Common;
public partial class Player2D : Node2D
{
[Export] private float _speed = 100f;
public override void _Process(double delta)
{
if (Input.IsActionPressed("move_right"))
Position = new Vector2(Position.X + (_speed * (float)delta), Position.Y);
if (Input.IsActionPressed("move_left"))
Position = new Vector2(Position.X - (_speed * (float)delta), Position.Y);
if (Input.IsActionPressed("move_up"))
Position = new Vector2(Position.X, Position.Y - (_speed * (float)delta));
if (Input.IsActionPressed("move_down"))
Position = new Vector2(Position.X, Position.Y + (_speed * (float)delta));
}
}
+1
View File
@@ -0,0 +1 @@
uid://dd7v316ib8fe7
+28
View File
@@ -0,0 +1,28 @@
using Godot;
namespace Babushka.scripts.CSharp.Common;
public partial class Player3D : CharacterBody3D
{
[Export] private float _speed = 1.0f;
[Export] private Camera3D _camera;
public override void _PhysicsProcess(double delta)
{
if (!IsOnFloor()) Velocity += Vector3.Down * (float) delta;
var inputDir = Input.GetVector("move_left", "move_right", "move_up", "move_down");
inputDir = inputDir.Rotated(-_camera.GlobalRotation.Y);
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
if (direction != Vector3.Zero)
{
Velocity = new Vector3(direction.X * _speed, Velocity.Y, direction.Z * _speed);
}
else
{
Velocity = Velocity.MoveToward(new Vector3(0, 0, 0), _speed);
}
MoveAndSlide();
}
}
+1
View File
@@ -0,0 +1 @@
uid://cp4snd0amnhfu