I have a knock back function and its basically like this, I omitted not necessary code:
Code: Select all
float angle, tmpYSub, tmpXSub;
tmpYSub = npc.x - knockback.x;
tmpYSub = npc.y - knockback.y;
if (sqrt(tmpYSub * tmpYSub + tmpXSub * tmpXSub) < knockback.range){
angle = atan2(tmpYSub, tmpXSub);
*npcHspeedInOut += knockback->intensity * cos(angle);
*npcVspeedInOut += knockback->intensity * sin(angle);
}
Im ok with replacing it with something that's much less accurate. Finding the distance is the next slowest part but "abs(tmpYSub) + abs(tmpXSub)" was a good trade off for me, so im mostly looking to replace atan2. Thanks for reading!