I had come up with a solution using the square root to calculate the distance traveled between two points to calculate the angle, irrlicht had something called "reciprocal_squareroot" that calculated the square root less accurately but faster, ironically, I didn't use any of these in the end. I solved it by using getRotation().rotationToDirection() and getting the absolute value to always get the same movement speed, without using square root, I got a better performance, I hope to post the results soon, but for now it looks something like this:
Code: Select all
if (EventReceiver.IsKeyDown(KEY_KEY_W)) {
core::vector3df forward = entities[0].node->getRotation().rotationToDirection();
f32 forwardXY = abs_(0 - forward.X) + abs_(0 - forward.Z);
forward.X = ((MoveSpeed * deltaTime) / (forwardXY))*forward.X;
forward.Z = ((MoveSpeed * deltaTime) / (forwardXY))*forward.Z;
forward.Y = zeroF32;
entities[0].node->setPosition(entities[0].node->getPosition() + forward);
}
Months of struggling with the math to get smooth and fast responsive movement without having to use the damn slow square root
it is likely that >getRotation().rotationToDirection() uses square root (I haven't seen the source code, so I don't know), but adding more square roots in a nested way probably generated the bottleneck.
**
If you are looking for people with whom to develop your game, even to try functionalities, I can help you, free.
CC0 man.
**