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