Parenting changes

This commit is contained in:
Marco Giacomelli 2024-02-27 17:16:55 +01:00
commit 6fbbe7ee4c
7 changed files with 225 additions and 160 deletions

View file

@ -1,11 +1,18 @@
using Godot;
using System;
using System.Diagnostics;
public partial class PlayerMovement : CharacterBody2D
{
[Export]
public int Speed { get; set; } = 400;
[Export]
public PackedScene BulletScene { get; set; }
[Export]
public Marker2D Muzzle {get;set;}
private AnimatedSprite2D _animatedSprite;
public override void _Ready()
@ -27,9 +34,22 @@ public partial class PlayerMovement : CharacterBody2D
public override void _Process(double delta)
{
HandleShoot();
SetAnimation();
}
private void HandleShoot()
{
if (Input.IsActionJustPressed("shoot"))
{
Bullet bullet = BulletScene.Instantiate<Bullet>();
Owner.AddChild(bullet);
bullet.Transform = Muzzle.GlobalTransform;
bullet.Position = this.Position;
}
}
private void SetAnimation()
{