Try new perspective for character, minor projectile fixes
This commit is contained in:
@@ -9,27 +9,35 @@ public partial class TestCharacter : CharacterBody3D
|
||||
[Export]
|
||||
private PackedScene _altFireProjectile;
|
||||
|
||||
public bool CanShoot { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CanShoot = true;
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("p1_fire"))
|
||||
if (Input.IsActionJustPressed("p1_fire") && CanShoot)
|
||||
Fire();
|
||||
if (Input.IsActionJustPressed("p1_altfire"))
|
||||
if (Input.IsActionJustPressed("p1_altfire") && CanShoot)
|
||||
AltFire();
|
||||
|
||||
Velocity = CalculateCharacterMovement();
|
||||
Velocity = CalculateCharacterMovement(delta);
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
private Vector3 CalculateCharacterMovement()
|
||||
private Vector3 CalculateCharacterMovement(double delta)
|
||||
{
|
||||
var velocity = Velocity;
|
||||
|
||||
var inputDir = Input.GetVector("p1_left", "p1_right", "p1_up", "p1_down");
|
||||
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
|
||||
if (direction != Vector3.Zero)
|
||||
{
|
||||
velocity.X = direction.X * _speed;
|
||||
velocity.Z = direction.Z * _speed;
|
||||
GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
|
||||
velocity.Z = direction.Z * _speed * 2;
|
||||
GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Forward);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -42,16 +50,20 @@ public partial class TestCharacter : CharacterBody3D
|
||||
private async void Fire()
|
||||
{
|
||||
var projectile = _fireProjectile.Instantiate<Projectile>();
|
||||
projectile.Position = Position + new Vector3(0f, 0f, -0.2f);
|
||||
projectile.Position = Position + new Vector3(0f, 1f, -1f);
|
||||
GetParent().AddChild(projectile);
|
||||
CanShoot = false;
|
||||
await ToSignal(GetTree().CreateTimer(projectile.Cooldown), "timeout");
|
||||
CanShoot = true;
|
||||
}
|
||||
|
||||
private async void AltFire()
|
||||
{
|
||||
var projectile = _altFireProjectile.Instantiate<Projectile>();
|
||||
projectile.Position = Position + new Vector3(0f, 0f, -0.2f);
|
||||
projectile.Position = Position + new Vector3(0f, 1f, -1f);
|
||||
GetParent().AddChild(projectile);
|
||||
CanShoot = false;
|
||||
await ToSignal(GetTree().CreateTimer(projectile.Cooldown), "timeout");
|
||||
CanShoot = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user