c++ - cocos2d-x determine where a object will be based off its vector -


in game want towers shoot enemy going time bullet reaches it.

i don't want bullet curve, want shoot directly estimated location based on speed unit moving , direction moving

my thought determine direction of enemy subtracting current position last position every time moves. lets direction (1,1)

after not 100% sure logic need do.

i thinking need know distance tower enemy determine time need estimate how far enemy going when bullet should reach it.

i don't know start one, if can give me pointers on how should handle solution.

in case of uniformly accelerated linear movement

x(t) = x0 + vx * t y(t) = y0 + vy * t 

where vx, vy projections of velocity v on coordinate axis. velocity vector scalar value speed, , direction in direction of movement. in case, if direction vector normalized, multiply speed velocity.

you know starting position: (x0, y0). need projections vx , vy. if w angle between x-axis , velocity, then

vx = v * cos(w) vy = v * sin(w) 

as angle: use atan2f function, or cocos2d function ccptoangle (which uses atan2f itself) normalized direction vector.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -