void normalizeVec(sf::Vector2f& moveVec) { if (moveVec.x != 0 && moveVec.y != 0) { float linelength = sqrt(pow(moveVec.x, 2) + pow(moveVec.y, 2)); moveVec.x /= linelength; moveVec.y /= linelength; } } this works well just keep moveVec between 0.0 - 1.0 and then after this function returns just multiply by moveSpeed or however your velocity system works
thanks very clear, needed this for player movement
Same
If you’re in Unity there is a .normalize for vector3’s
Me 2
void normalizeVec(sf::Vector2f& moveVec)
{
if (moveVec.x != 0 && moveVec.y != 0)
{
float linelength = sqrt(pow(moveVec.x, 2) + pow(moveVec.y, 2));
moveVec.x /= linelength;
moveVec.y /= linelength;
}
}
this works well just keep moveVec between 0.0 - 1.0 and then after this function returns just multiply by moveSpeed or however your velocity system works
Same
needed this to make the enemy follow the player lol thanks!
Very clear video, thank you !
thanks
Like If you're here for game dev
que video bom
Hello
sup