push object away from explosion center
Blitz3D Forums/Blitz3D Programming/push object away from explosion center
| ||
i'm not sure how to make this happen... if an enemy_type explodes, i want every enemy within a certain radius to move away from the explosion a specific amount, say '10' for the sake of argument. i can't get my head around the math. this is a 2d on 3d game, by the way. i have if e\myexplode_pushesothers for ee.enemy_type = each enemy_type if dist2d(entityx(ee\piv,1),entityz(ee\piv,1),entityx(e\piv,1),entityz(e\piv,1)) < 5 move ee\piv 5 away from e\piv without turning him endif next endif it's that middle part i'm not sure on - do i maybe make a new pivot at the enemy to move, point it towards the explosion, turn it 180 degrees the other way, and translate to it, then remove the pivot? this seems to make sense. how do i do the translate to a spot? ow my head hurts. |
| ||
push_distance#=10 explosion_radius#=100 dx#=enemy_x - explosion_x dy#=enemy_y - explosion_y distance#=sqr(dx*dx+dy*dy) if distance<explosion_radius ;normalize (create vector length 1) dx=dx/distance dy=dy/distance enemy_x=enemy_x+(dx*push_distance) enemy_y=enemy_y+(dy*push_distance) endif |