0 votes

func shoot():
var projectile = load("res://Bullets/UnchargedProjectile.tscn")
var bullet = projectile.instance()
bullet.position = getglobalposition()
getparent().addchild(bullet)

Godot version Godot Engine v3.3.stable.official
in Engine by (19 points)

2 Answers

+1 vote

im also not that far, but i watched a ton of videos the last days to get a feeling.

https://www.youtube.com/watch?v=isA7P9ulBwE

i remember this one from yesterday, he is showcasing and at one point talking about the projectile velocity.

this should give a an idea for a working approach i guess.

hope this helps in finding a solution :)

by (40 points)

Thanks, this helped :)

0 votes

One way to achieve this is using a Timer, which you could add as a node in the editor, or via code.

  • Add a new timer node to your player, and set the wait time to however long you want it to be between shots – say, 0.1 seconds.
  • Also set the timer to "One Shot"
  • In your code, when you check whether the user is firing (presumably to call your shoot method), also check that the timer is stopped. This will prevent multiple shots being fired while the timer is running.
  • Finally, at the end of your shoot method, start the timer so that another shot can't be fired straight away.

Your code may end up looking something like tihs:

func _process(delta):
    if Input.is_action_pressed("fire") and $CooldownTimer.is_stopped():
        shoot()

func shoot():
    # your existing code
    $CooldownTimer.start()

I also recorded a video of this setup and posted it here, in case it's useful! https://www.youtube.com/watch?v=85A7OaAkAxg

by (28 points)
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 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 webmaster@godotengine.org with your username.