finally fix firing - laser now spawn in correct position
This commit is contained in:
parent
eb1ad24f21
commit
e55513d1dc
|
|
@ -12,15 +12,12 @@ scale = Vector2(0.6, 0.6)
|
||||||
script = ExtResource("1_ctmji")
|
script = ExtResource("1_ctmji")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
position = Vector2(0, -27)
|
|
||||||
shape = SubResource("CapsuleShape2D_odhrn")
|
shape = SubResource("CapsuleShape2D_odhrn")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
position = Vector2(0, -28)
|
|
||||||
texture = ExtResource("2_nq6d6")
|
texture = ExtResource("2_nq6d6")
|
||||||
|
|
||||||
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
|
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
|
||||||
position = Vector2(0, -27.5)
|
|
||||||
scale = Vector2(0.5, 2.75)
|
scale = Vector2(0.5, 2.75)
|
||||||
|
|
||||||
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
|
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
|
||||||
|
|
|
||||||
|
|
@ -5,23 +5,31 @@ public partial class game : Node2D
|
||||||
{
|
{
|
||||||
public Node Lasers = null;
|
public Node Lasers = null;
|
||||||
public CharacterBody2D Player = null;
|
public CharacterBody2D Player = null;
|
||||||
public Area2D Laser = null;
|
//public Area2D Laser = null;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
//Lasers = GetNode<Node>("Lasers");
|
Lasers = GetNode<Node>("Lasers");
|
||||||
//Player = GetNode<CharacterBody2D>("Player");
|
Player = GetNode<CharacterBody2D>("Player");
|
||||||
//Laser = GetNode<Area2D>("Laser");
|
//Laser = GetNode<Area2D>("Laser");
|
||||||
//Callable OnLaserShot = new Callable(this, "_on_player_laser_shot");
|
//Callable OnLaserShot = new Callable(this, "_on_player_laser_shot");
|
||||||
//Player.Connect("LaserShot", OnLaserShot);
|
//Player.Connect("LaserShot", );
|
||||||
|
var p = new player();
|
||||||
|
//var l = new Laser();
|
||||||
|
p.LaserShot += _on_player_laser_shot;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Player.ShootLaser += () => _on_player_laser_shot(Laser);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _on_player_laser_shot(Area2D Laser)
|
public void _on_player_laser_shot(Area2D Laser)
|
||||||
{
|
{
|
||||||
Lasers.AddChild(Laser);
|
Lasers.AddChild(Laser);
|
||||||
|
GD.Print(Laser.Position);
|
||||||
|
GD.Print(Player.Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ public partial class player : CharacterBody2D
|
||||||
[Export]
|
[Export]
|
||||||
public int MainSpeed { get; set; } = 10;
|
public int MainSpeed { get; set; } = 10;
|
||||||
[Export]
|
[Export]
|
||||||
public int StrafeSpeed { get; set; } = 4;
|
public int StrafeSpeed { get; set; } = 5;
|
||||||
[Export]
|
[Export]
|
||||||
public float RotationSpeed { get; set; } = 2f;
|
public float RotationSpeed { get; set; } = 2f;
|
||||||
|
|
||||||
|
|
@ -43,12 +43,17 @@ public partial class player : CharacterBody2D
|
||||||
public void ShootLaser()
|
public void ShootLaser()
|
||||||
{
|
{
|
||||||
Node2D Laser = LaserScene.Instantiate<Node2D>();
|
Node2D Laser = LaserScene.Instantiate<Node2D>();
|
||||||
Laser.Position = LaserSpawn.Position;
|
Laser.Position = LaserSpawn.GlobalPosition;
|
||||||
Laser.Rotation = Rotation;
|
Laser.Rotation = Rotation;
|
||||||
GD.Print("shoooot");
|
GD.Print("shoooot");
|
||||||
|
var l = new Laser
|
||||||
|
{
|
||||||
|
Position = new Vector2(LaserSpawn.Position.X, LaserSpawn.Position.Y),
|
||||||
|
Rotation = Rotation
|
||||||
|
};
|
||||||
EmitSignal(SignalName.LaserShot, Laser);
|
EmitSignal(SignalName.LaserShot, Laser);
|
||||||
//GetParent().AddChild(Laser);
|
//GetParent().AddChild(Laser);
|
||||||
AddChild(Laser);
|
//AddChild(Laser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue