Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Cofefe |
Hi there! So, in a project that I’m working on I am creating an enemy that can throw bricks at the player. I’ve set it up so that there is a Position2D Node called “Gun” with a function “_shoot()” that creates the “Brick.tscn” projectile. Function code is below if you want to see:
func _shoot(
cooldown_time = 0.25, #int: cooldown_time
burst_size = 3,
bullet_type = preload("res://Scenes/MAGA Man/MAGA Bullet.tscn"),
direction = Vector2(1, 0),
charge_level = 1
):
cooldown = cooldown_time
if bullet_count < burst_size:
bullet_timer = 0
bullet_count += 1
var bullet = bullet_type.instance()
bullet.global_position = global_position
bullet.direction = direction
bullet.charge_level = charge_level
bullet.set_as_toplevel(true)
add_child(bullet)
return true
else:
return false
Note that I reuse this function in many objects.
I have already been successful getting the enemy to throw bricks using code, but wanted to try it using the AnimationPlayer. So, I added a call function track to my “throwing” animation and filled the parameters out appropriately. The enemy object can throw the bricks now, but only in one direction. In my game I will be placing many enemies throughout the game world, and they will throw bricks in different directions depending on which way they are facing. The question is: Can I input code as the value for an argument? I’ve tried simply typing “=scale.x”, but that just sets the value to 1. Is there another way to do this or should I just stick with doing it through code?
Thanks