As the title suggest I have a projectile which AI will shoot at players. The available data is the distance between the two and the velocity being used make the projectile motion formula here 1/2 sin^-1(g * x / velocity^2)
fit well. However, when running my project it shoots near my player but undershoots it every time no matter where I am by a tad bit. This is the code I am using for this:
func set_velocity(from_pos, target_pos):
var dist_to_object = from_pos.distance_to(target_pos)
rotation.x = -(PI/2 -(0.5 * asin((9.8 * dist_to_object) / (speed ** 2))))
linear_velocity = (global_transform.basis.z * speed)
#apply_impulse(Vector3.ZERO, global_transform.basis.z * speed) - originally attempted to use but seems to be broken, as only applying it for one run doesn't cause any movement on my object.
print(linear_velocity)
And this is run from a parent enemy using this code
var rock = rock_scene.instantiate()
rock.enemy_group = enemy_group
rock_spawn_point.add_child(rock)
rock.set_velocity(global_position, enemy.global_position)
rock.look_at(enemy.global_position, Vector3.UP)
rock.rotate_y(PI) #otherwise faces backwards
Any help would be greatly appreciated!