0

Lets suppose tha my movement method my W goes towards north(just figuretvly) and my E goes towards east, If I rotate my camera to east I want my W to insted goes to north, goes towards east and my E to go towards south how do I do it?

Code:

public void OnMovement(InputAction.CallbackContext value)
{
    movement2D = value.ReadValue<Vector2>();
    movement2D.Normalize();
    direction = new Vector3(movement2D.x, 0, movement2D.y);
    direction.Normalize();

}

void ApplyMovement() { isWalking = direction.x != 0 || direction.z != 0;

float currentSpeed = speed * (isRunning &amp;&amp; !isCrouching ? speedWhileRunningMultiplier : isCrouching ? speedWhileCrouchingMultiplier : 1);
Vector3 currentDirection = playerCamera.DirectionToMoveByCamera(direction);
controller.Move(currentDirection * currentSpeed * Time.deltaTime);
// ApplyAnimation();

}

void ApplyRotation() { if (movement2D.sqrMagnitude == 0) return;

if (playerCamera.PlayerShouldRotateByCameraAngle || playerCamera.isFirstPerson)
{
    Debug.Log(&quot;sssssss&quot;);
    playerTransform.rotation = Quaternion.Euler(0.0f, playerCamera.cameraTransform.transform.eulerAngles.y, 0.0f);
}
else
{
    float targetAngle = Mathf.Atan2(playerCamera.cameraTransform.transform.eulerAngles.x, playerCamera.cameraTransform.transform.eulerAngles.z) * Mathf.Rad2Deg;
    float angle = Mathf.LerpAngle(transform.eulerAngles.y, targetAngle, smoothTime * Time.deltaTime);
    playerTransform.rotation = Quaternion.Euler(0.0f, angle, 0.0f);
}

} public Vector3 DirectionToMoveByCamera(Vector3 direction) { if (PlayerShouldRotateByCameraAngle || isFirstPerson) { return Quaternion.AngleAxis(cameraTransform.transform.rotation.eulerAngles.y, Vector3.up) * direction; }

return direction;

}

the method DirectionToMoveByCamera when I'm in first person my W goes towards where my camera is poiting but If I like i'm in third person, my W A S D is not relative to where my camera is poiting(to the front of my player) note: PlayerShouldRotateByCameraAngle has nothing to do with it

Jamelaumn
  • 15
  • 4

0 Answers0