0 votes

Hello, I've been trying to wrap my head around a proper implementation of arrow shooting. In order for you to better understand a situation, I'm going to present to you a setup I've conjured up for my game. Well, there's two characters, namely an archer mob and a player. Apparently, archer mob plays a role of arrow shooter. Once player enters dangerous zone, archer gets ready to shoot some arrows. Pretty simple, isn't it? The only problem I've encountered during my coding adventures was a physics related to projectile motion of an arrow. Here's what I managed to construct so far

func _process(delta):
if launched:
  # Notice: angle chosen is -pi/4 (i find it well suited for initial conditions)
  xt = launchSpeed * cos(angle) * delta
  yt = (launchSpeed * sin(angle) * delta) - (1/2 * consts.g * delta * delta)
  position += Vector2(xt, yt)   
  angle = atan2(yt, xt)
  rotation += deg2rad(1)

Should I update an angle the way I did in the code? Is there a better way to do it?
Thanks in advance

in Engine by (14 points)

I have a video that might help you. It's from GameEndeavor, and in it he shows how he shoots physics-based cannonballs. You might be to tweak the code to be able to suit your needs: https://www.youtube.com/watch?v=_kA1fbBH4ug

Not sure if this is going to help, but hopefully it does.

Thanks! I'll definitely watch it.

1 Answer

+1 vote

I think it should. Towerfall would make a good reference for this sort of thing.

As for how, it's hard to say without trying it out myself, but here's what you've got should work. One thing to do for sure would be to set the pivot point of the arrow to the tip, so that the feather of the arrow can rotate and trail behind the sharp end.

by (167 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.