I'm having an issue with my projectile traveling accurately toward the end destination. Take a look at this short video, you'll see the problem at 0:10.
Here is the straight movement setup for projectiles:
#define abs_x(a) (a.x * TILE_SIZE) + (ismovable(a) ? (a:step_x) : (0))
#define abs_y(a) (a.y * TILE_SIZE) + (ismovable(a) ? (a:step_y) : (0))
proc/straight_travel(atom/end)
// end is the atom the projectile should be traveling toward.
var/delta_x = abs_x(end) - abs_x(src)
var/delta_y = abs_y(end) - abs_y(src)
var/distance = sqrt(delta_x * delta_x + delta_y * delta_y)
var/move_speed = step_size
vel_x = (delta_x / distance) * move_speed
vel_y = (delta_y / distance) * move_speed
while(src)
sleep(tick_speed)
var/m = Move(loc, dir,
step_x + vel_x,
step_y + vel_y)
if(!m)
break
dispose()
I'm looking to be lead in the right direction, but any help is appreciated.
I have a strong feeling it has to do with not taking the projectile's size into account, because the larger the projectile, the easier it is for it to miss. I'm not too experienced making projectile systems though, and as such I'm looking to learn any and everything about the topic. Thanks.
Try using mutual centers rather than the bottom-left corner of both.