- #1
Darkmisc
- 203
- 27
- TL;DR Summary
- I'd like enemies to fire a shot once they get behind the player. I have an if-statement to fire a shot if position<x. This works. However, the if-statement doesn't work if I write "if position<x-100".
Hi everyone
I'm making a shoot 'em up in which enemies travel right to left towards the player. If they get behind the player, they are supposed to fire a shot at the player.
The code below for the enemy works, but I'd like a slight delay before the shot is fired.
However, the enemy won't fire if I have this at line 6
Does anyone know why?
Thanks
EDIT: I have the player in the middle of the screen when the enemies pass, so I don't think it's because the enemies are off-screen by the time they are 100 pixels behind the player.
Also, I've used position.x<shoot_pos - rand_range(0, 200) and they've never fired with that code either.
I'm making a shoot 'em up in which enemies travel right to left towards the player. If they get behind the player, they are supposed to fire a shot at the player.
The code below for the enemy works, but I'd like a slight delay before the shot is fired.
enemy:
func _physics_process(delta):
position+= speed*movement_vector*delta
if position.x <=Global.player_pos.x and shot_fired==false:
launch_proximity()
shoot_laser:
func launch_proximity():
shot_fired=true
player_pos=Global.player_pos.x
shoot_pos = player_pos
if position.x<shoot_pos:
print("bam")
var child_node = $EnemyBarrel/Muzzle
Global.rot = $EnemyBarrel.rotation
var l = LASER.instance()
get_parent().add_child(laser_parent)
laser_parent.add_child(l)
l.global_position = child_node.global_position
l.rotation = $EnemyBarrel.rotation
add_child(l)
However, the enemy won't fire if I have this at line 6
line 6:
if position.x<shoot_pos -100:
Thanks
EDIT: I have the player in the middle of the screen when the enemies pass, so I don't think it's because the enemies are off-screen by the time they are 100 pixels behind the player.
Also, I've used position.x<shoot_pos - rand_range(0, 200) and they've never fired with that code either.
Last edited: