Translated Player Scripts from GDScript to C#
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
[gd_scene load_steps=5 format=3 uid="uid://dbd1niu3tp8y5"]
|
[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="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"]
|
[ext_resource type="Script" uid="uid://c81bn1w8o0n2n" path="res://scripts/CSharp/Common/CameraPivot.cs" id="3_3trg2"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_1vdrh"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_1vdrh"]
|
||||||
@@ -10,11 +10,11 @@ height = 0.234557
|
|||||||
|
|
||||||
[node name="Player3d" type="Node3D"]
|
[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_layer = 16
|
||||||
collision_mask = 17
|
collision_mask = 17
|
||||||
script = ExtResource("1_08wm4")
|
script = ExtResource("1_3trg2")
|
||||||
SPEED = 0.5
|
_camera = NodePath("CameraPivot/SubPivot/Camera3D")
|
||||||
|
|
||||||
[node name="Sprite" type="Sprite3D" parent="CharacterBody3D"]
|
[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)
|
transform = Transform3D(0.04, 0, 0, 0, 0.04, 0, 0, 0, 0.04, 0, 0.110813, 0)
|
||||||
|
|||||||
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://dd7v316ib8fe7
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://cp4snd0amnhfu
|
||||||
Reference in New Issue
Block a user