mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 12:45:55 +00:00
Added crosshair
This commit is contained in:
parent
5012527bae
commit
9e3c75ca1d
5 changed files with 72 additions and 2 deletions
|
|
@ -7,6 +7,9 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
[Export]
|
||||
public int Speed { get; set; } = 400;
|
||||
|
||||
[Export]
|
||||
public float CrosshairDistance { get; set; } = 10f;
|
||||
|
||||
[Export]
|
||||
public PackedScene BulletScene { get; set; }
|
||||
|
||||
|
|
@ -19,9 +22,13 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
|
||||
private Vector2 _facingDirection { get; set; }
|
||||
|
||||
private Sprite2D _crosshair;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("./Smoothing2D/AnimatedSprite2D");
|
||||
_crosshair = GetNode<Sprite2D>("./Crosshair");
|
||||
|
||||
_movementDirection = Vector2.Zero;
|
||||
_facingDirection = Vector2.Zero;
|
||||
}
|
||||
|
|
@ -53,7 +60,7 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
Owner.AddChild(bullet);
|
||||
bullet.Transform = Muzzle.GlobalTransform;
|
||||
bullet.Position = this.Position;
|
||||
bullet.SetDirection(this._movementDirection);
|
||||
bullet.SetDirection(this._facingDirection);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -95,6 +102,19 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
return Input.GetVector("left", "right", "up", "down");
|
||||
}
|
||||
|
||||
private Vector2 CalculateCrosshairPosition()
|
||||
{
|
||||
|
||||
return _facingDirection * CrosshairDistance;// + this.Position;
|
||||
|
||||
//var angle = Mathf.Atan2(this.Position.X, this.Position.Y);
|
||||
|
||||
|
||||
//var cPos = new Vector2(this.Position.X + CrosshairDistance * Godot.Mathf.Cos(angle), this.Position.Y + CrosshairDistance * Godot.Mathf.Sin(angle));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_movementDirection = GetInput();
|
||||
|
|
@ -104,5 +124,8 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
Velocity = _movementDirection * (float)(Speed * delta);
|
||||
|
||||
MoveAndSlide();
|
||||
|
||||
_crosshair.Position = CalculateCrosshairPosition();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue