From e91f2c9f403522b22b730f777baa354b9a9cfedc Mon Sep 17 00:00:00 2001 From: LMBishop <13875753+LMBishop@users.noreply.github.com> Date: Sat, 29 Oct 2022 18:00:46 +0100 Subject: Fix bullets --- Bullet.gd | 18 ------------------ KinematicBody2D.gd | 7 +------ Node2D.tscn | 6 +++--- 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/Bullet.gd b/Bullet.gd index be4e0bc..b2058ba 100644 --- a/Bullet.gd +++ b/Bullet.gd @@ -5,27 +5,9 @@ var velocity = Vector2() var target = Vector2.ZERO #var player = load("") var shot = false; -func get_input(): - velocity = Vector2() - if Input.is_action_pressed("right"): - velocity.x += 1 - if Input.is_action_pressed("left"): - velocity.x -= 1 - if Input.is_action_pressed("down"): - velocity.y += 1 - if Input.is_action_pressed("up"): - velocity.y -= 1 - - velocity = velocity.normalized() * speed - - func _physics_process(delta): - - - - target = get_global_mouse_position() if(Input.is_action_pressed("click") && shot == false): velocity = global_position.direction_to(target) * speed diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd index 03dd45f..3be3afc 100644 --- a/KinematicBody2D.gd +++ b/KinematicBody2D.gd @@ -18,15 +18,10 @@ func get_input(): velocity = velocity.normalized() * speed func _physics_process(delta): - - - get_input() globals.playerPos = global_position velocity = move_and_slide(velocity) if Input.is_action_just_pressed("click"): var obj = spawn_object.instance() obj.position = get_position() - obj.position.x -= 500 - obj.position.y -= 250 - add_child(obj) + get_owner().add_child(obj) diff --git a/Node2D.tscn b/Node2D.tscn index ec9f7c3..a471e7e 100644 --- a/Node2D.tscn +++ b/Node2D.tscn @@ -15,12 +15,12 @@ _data = { script = ExtResource( 3 ) enemy_scene = ExtResource( 5 ) +[node name="Bullet" parent="." instance=ExtResource( 4 )] +position = Vector2( 548, 225 ) + [node name="KinematicBody2D" parent="." instance=ExtResource( 2 )] position = Vector2( 544, 216 ) -[node name="Bullet" parent="KinematicBody2D" instance=ExtResource( 4 )] -position = Vector2( 4, 9 ) - [node name="Node" type="Node" parent="."] [node name="HUD" parent="." instance=ExtResource( 1 )] -- cgit v1.2.3-70-g09d2