Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Vector based unit movement

Vector based unit movement

Calin
Calin
DreamLand editor · · 1 min read
23,938 2

Up to this point I have been using a unique code snippet for each direction of movement. These days I managed to switch to using vectors for movement. I have the same code for all directions now

float VectorX = NextNodeX - UpixPosX;
float VectorY = NextNodeY - UpixPosY;
float VecLength = sqrt(VectorX * VectorX + VectorY * VectorY);
float SpeedPercent = (0.016 * 100) / VecLength;
float AdvanceX = (VectorX * SpeedPercent) / 100;
float AdvanceY = (VectorY * SpeedPercent) / 100;

UpixPosX = UpixPosX + AdvanceX;
UpixPosY = UpixPosY + AdvanceY;

Now I have to figure out steering given this new approach

Discussion

Loading comments...