starfighter/MB_FYP/script/player.cs

36 lines
1,015 B
C#
Raw Normal View History

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();
}
}