From abc2bb337922e5a2397b2f8ece3cd51d7082e0aa Mon Sep 17 00:00:00 2001 From: maximus Date: Sun, 19 Nov 2023 20:24:14 +0000 Subject: [PATCH] basic player movement added - rotation and thrust --- MB_FYP/script/player.cs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 MB_FYP/script/player.cs diff --git a/MB_FYP/script/player.cs b/MB_FYP/script/player.cs new file mode 100644 index 0000000..78d3048 --- /dev/null +++ b/MB_FYP/script/player.cs @@ -0,0 +1,36 @@ +using Godot; +using System; + +public partial class player : CharacterBody2D +{ + [Export] + public Vector2 ScreenSize; + + [Export] + public int Speed { get; set; } = 10; + + [Export] + public float RotationSpeed { get; set; } = 2f; + + private int _rotationDirection; + + public void GetInput(){ + /*LookAt(GetGlobalMousePosition()); //used for mouse-based rotation and movement + Velocity = Transform.X * Input.GetAxis("down", "up") * Speed; + */ + + _rotationDirection = (int)Input.GetAxis("left", "right"); + Velocity += (Transform.Y * Input.GetAxis("strafe_left", "strafe_right") + Transform.X * Input.GetAxis("down", "up")) * Speed; + } + + public override void _Ready(){ // on init + GD.Print("afa"); + ScreenSize = GetViewportRect().Size; + } + + public override void _PhysicsProcess(double delta){ // every frame + GetInput(); + Rotation += _rotationDirection * RotationSpeed * (float)delta; + MoveAndSlide(); + } +} \ No newline at end of file