basic player movement added - rotation and thrust
This commit is contained in:
parent
24dd2c9814
commit
abc2bb3379
36
MB_FYP/script/player.cs
Normal file
36
MB_FYP/script/player.cs
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue