mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:55:35 +00:00
Directional shooting
This commit is contained in:
parent
155d210e31
commit
65ce30a2a4
7 changed files with 158 additions and 10 deletions
|
|
@ -11,13 +11,19 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
public PackedScene BulletScene { get; set; }
|
||||
|
||||
[Export]
|
||||
public Marker2D Muzzle {get;set;}
|
||||
public Marker2D Muzzle { get; set; }
|
||||
|
||||
private AnimatedSprite2D _animatedSprite;
|
||||
|
||||
private Vector2 _movementDirection { get; set; }
|
||||
|
||||
private Vector2 _facingDirection { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
||||
_movementDirection = Vector2.Zero;
|
||||
_facingDirection = Vector2.Zero;
|
||||
}
|
||||
|
||||
/*public override _Process(float _delta)
|
||||
|
|
@ -41,12 +47,13 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
private void HandleShoot()
|
||||
{
|
||||
if (Input.IsActionJustPressed("shoot"))
|
||||
{
|
||||
{
|
||||
Debug.WriteLine("Shoot");
|
||||
Bullet bullet = BulletScene.Instantiate<Bullet>();
|
||||
Owner.AddChild(bullet);
|
||||
bullet.Transform = Muzzle.GlobalTransform;
|
||||
bullet.Position = this.Position;
|
||||
bullet.SetDirection(this._movementDirection);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -89,9 +96,12 @@ public partial class PlayerMovement : CharacterBody2D
|
|||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var inputDirection = GetInput();
|
||||
Velocity = inputDirection * (float)(Speed * delta);
|
||||
{
|
||||
_movementDirection = GetInput();
|
||||
if (_movementDirection != Vector2.Zero) {
|
||||
_facingDirection = _movementDirection;
|
||||
}
|
||||
Velocity = _movementDirection * (float)(Speed * delta);
|
||||
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue