0 votes

I'm looking to rotate the bullets being shot based on the amount, I'm not sure how to do so (ex. if I chose 3 for bullet amount, it'd shoot like a shotgun in a cone). I'm new to godot so sorry If there's a very easy and clear answer that I should know about already.

My function:

#spawning
for i in info["bullet_amount"]:
    var bullet = bullet_path.instance()
    bullet.position = $Position2D.global_position
    bullet.rotation = self.rotation #rotate base on amount
    get_parent().get_parent().add_child(bullet)
#moving
    bullet.speed = info["bullet_speed"]
    bullet.velocity = get_global_mouse_position() - bullet.position #moves in another script
Godot version v3.5.1 stable
in Engine by (15 points)
edited by

1 Answer

0 votes
Best answer

presumably something like this? where spread is the total rotation of the bullets

bullet.rotation = rotation + spread / info.bullet_amount - spread / 2
by (8,150 points)
selected by

I played around with it a little but I can't get spread to equal the total rotation of the bullets, here's my code so you can show me what I'm doing wrong:

#spawning
for i in info["bullet_amount"]:
    var bullet = bullet_path.instance()
    bullet.position = $Position2D.global_position
    var spread = 0 + bullet.rotation # no idea what to do here
    bullet.rotation = self.rotation + spread / info["bullet_amount"] - spread / 2
    var direction = bullet.global_transform.basis_xform(Vector2.RIGHT)
    get_parent().get_parent().add_child(bullet)
#moving
    bullet.speed = info["bullet_speed"]
    bullet.velocity = direction

spread should be outside the for loop and should be the total spread of the bullets (pi/4 rad, pi/2 rad, etc)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.