[Tutorial] Rotation 180º Char Remake

Joined
Nov 28, 2022
Messages
151
Reaction score
50
[Tutorial] Rotation 180º Char [FrontEnd]

Only one code has been changed, the main code is quoted from this person@LukasCCB


Add this instead of this code and the character will return to its previous state after being thinned

C++:
int mMX = Fare->m_MouseMoveX; float glb_MouseSensAdj = 1.0f; // 0.1 ile 1.0 arasında float mmoveX = static_cast<float>(-mMX) * glb_MouseSensAdj; if (Mouse->IsPressed(r3dMouse::mRightButton)) { playerRot += mmoveX; if (playerRot > 180) playerRot = 180; if (playerRot < -180) playerRot = -180; } else if(m_needPlayerRenderingRequest==3) // oyun ekranını oyna m_Player->SetPosition(playerPosCreate);

Code:
// Target rotation value
float targetRot = 0.0f;
// Rotation speed (adjustable)
float rotationSpeed = 1.0f;

if (!Mouse->IsPressed(r3dMouse::mRightButton)) {
    // If the character's rotation is different from the target rotation, reverse the rotation movement
    if (playerRot != targetRot) {
        // Determine the direction of rotation
        float rotationDirection = (playerRot > targetRot) ? -1.0f : 1.0f;
        // Update the rotation
        playerRot += rotationSpeed * rotationDirection;

        // If the rotation speed is slow and it's approximately close to the target, lock the rotation to zero
        if (fabs(playerRot - targetRot) < rotationSpeed) {
            playerRot = targetRot;
        }
    }
}

int mMX = Mouse->m_MouseMoveX;
float glb_MouseSensAdj = 1.0f;
float mmoveX = static_cast<float>(-mMX) * glb_MouseSensAdj;

if (Mouse->IsPressed(r3dMouse::mRightButton)) {
    playerRot += mmoveX;
    if (playerRot > 180) playerRot = 180;
    if (playerRot < -180) playerRot = -180;
}
 
Back