Randomly appearing bullets

hi there and good night(if it’s night in your country now), i want to add one small feature in my project, i have three different types of bullets(there is just one example shooting), and i want them to shoot randomly changing each other, how can i do so?


there is a code for that bullet

var bullet = preload("res://scenes/bullet.tscn")
func fire():
	var bullet_exemplar = bullet.instantiate()
	bullet_exemplar.position = get_global_position()
	bullet_exemplar.rotation_degrees = rotation_degrees
	bullet_exemplar.apply_impulse(Vector2(bullet_speed, 0),Vector2().rotated(rotation))
	get_tree().get_root().call_deferred("add_child", bullet_exemplar)
if Input.is_action_just_pressed("shoot"):
		fire()

help me please

You probably mean to use apply_central_impulse. The second parameter in apply_impulse is where to apply the force, a rotated 0 vector doesn’t make much sense here and will result in very strange spinning.

Try this instead.

bullet_exemplar.apply_central_impulse(Vector2.RIGHT.rotated(rotation) * bullet_speed)
1 Like

it’s almost what i wanted, but i know now how to solve my problem, thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.