diff --git a/prefabs/Player3D.tscn b/prefabs/Player3D.tscn index 0d13e9b..05ae293 100644 --- a/prefabs/Player3D.tscn +++ b/prefabs/Player3D.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=5 format=3 uid="uid://dbd1niu3tp8y5"] +[ext_resource type="Script" uid="uid://cp4snd0amnhfu" path="res://scripts/CSharp/Common/Player3D.cs" id="1_3trg2"] [ext_resource type="Texture2D" uid="uid://cvn2p215jq2am" path="res://graphics/mockups/concerned.png" id="1_5jpx2"] -[ext_resource type="Script" uid="uid://dke381v8tafqn" path="res://scripts/GdScript/player_3d.gd" id="1_08wm4"] [ext_resource type="Script" uid="uid://c81bn1w8o0n2n" path="res://scripts/CSharp/Common/CameraPivot.cs" id="3_3trg2"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_1vdrh"] @@ -10,11 +10,11 @@ height = 0.234557 [node name="Player3d" type="Node3D"] -[node name="CharacterBody3D" type="CharacterBody3D" parent="."] +[node name="CharacterBody3D" type="CharacterBody3D" parent="." node_paths=PackedStringArray("_camera")] collision_layer = 16 collision_mask = 17 -script = ExtResource("1_08wm4") -SPEED = 0.5 +script = ExtResource("1_3trg2") +_camera = NodePath("CameraPivot/SubPivot/Camera3D") [node name="Sprite" type="Sprite3D" parent="CharacterBody3D"] transform = Transform3D(0.04, 0, 0, 0, 0.04, 0, 0, 0, 0.04, 0, 0.110813, 0) diff --git a/scripts/CSharp/Common/Player2D.cs b/scripts/CSharp/Common/Player2D.cs new file mode 100644 index 0000000..18e4e84 --- /dev/null +++ b/scripts/CSharp/Common/Player2D.cs @@ -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)); + } +} diff --git a/scripts/CSharp/Common/Player2D.cs.uid b/scripts/CSharp/Common/Player2D.cs.uid new file mode 100644 index 0000000..b0a5fd9 --- /dev/null +++ b/scripts/CSharp/Common/Player2D.cs.uid @@ -0,0 +1 @@ +uid://dd7v316ib8fe7 diff --git a/scripts/CSharp/Common/Player3D.cs b/scripts/CSharp/Common/Player3D.cs new file mode 100644 index 0000000..8a06a84 --- /dev/null +++ b/scripts/CSharp/Common/Player3D.cs @@ -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(); + } +} diff --git a/scripts/CSharp/Common/Player3D.cs.uid b/scripts/CSharp/Common/Player3D.cs.uid new file mode 100644 index 0000000..db3e972 --- /dev/null +++ b/scripts/CSharp/Common/Player3D.cs.uid @@ -0,0 +1 @@ +uid://cp4snd0amnhfu