Hi, as the topic says, I'm trying to implement artillery in my rts project. I know the position of the enemy at the moment of the shot, but I can't figure out how to create a fake arch that the projectile is following until it hits.

my code until now looks like this, which kind of works, but the arch is too long so it completely misses the target

    # move the projectile towards the enemy (projectile is already in line with the target upon instancing)
	set_translation(get_translation()-get_transform().basis.z * muzzle_velocity * delta) 

    # calculate the distance (target_vec = transform of target during shot)
	var current_dist = self.global_transform.origin.distance_to(target_vec)

	# try to use a function to displace the y value of the projectile to have an arch like flight path
    var flight_vec = ((-(current_dist*current_dist)+enemy_distance*current_dist))/(enemy_distance) 

	# apply y change (start_pos = muzzle height of the firing unit)
    transform.origin.y = flight_vec + start_pos 

Or maybe someone has a better idea on how to implement the artillery projectile?

Thanks for reading

Sorry I don't quite understand how your code could be used in my case. Could you explain?

i.e. what is the variable arch_num_points and where does it come from?

I only know how to pre-calculate the postions for x steps without collisions. I dont how to actually draw you arch in 3D.

There are 3 variables I have declared arch_num_points = how many steps should be pre-calculated (e.g. 100) velocity = the current objects velocity gravity = your gravity

Last line is related to Line2D and you probably want to add pos to an array and draw your arch after you have all your points.

I was able to figure it out, with my original code :smile:

my final code looks like this


#move projectile in target direction
set_translation(get_translation()-get_transform().basis.z * muzzle_velocity * delta)
# calculate distance to targtet
var current_dist = Vector3(self.global_transform.origin.x,0,self.global_transform.origin.z).distance_to(target_vec) 
# calulate arch
var flight_vec = ((-(current_dist*current_dist)+enemy_distance*current_dist))/(enemy_distance/2) 
# Apply y value to current transform
transform.origin.y = flight_vec + offset_pos
# Remove influence of Muzzle height, so that the projectile reaches the target position with y=0
	if offset_pos <= 0:
		offset_pos = 0
	else:
		offset_pos = ((current_dist/enemy_distance)-0.33) * start_pos
10 months later