Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.3 kB
2
Indexable
Never
if (SceneManager.GetActiveScene().name == "WobblyIsland" || SceneManager.GetActiveScene().name == "ArcadeLobby" || SceneManager.GetActiveScene().name == "WobblyRun" || SceneManager.GetActiveScene().name == "Quarry")
{
    if (!player)
        player = GetPlayerCharacter();
    if (flight && player)
    {
        if (ragdoll == null)
        {
            if (player == null)
                player = GetPlayerCharacter();
            if (player != null)
               ragdoll = player.GetComponent<RagdollController>();
        }
        else
        {
            if (ragdoll != null)
                ragdoll.LockRagdollState();
            else
                Log("Can't find ragdoll!");
        }
        if (Input.GetKey(KeyCode.Space))
        {
            playerPos = new Vector3(playerPos.x, playerPos.y + vertSpeed, playerPos.z);
        }
        if (Input.GetKey(KeyCode.LeftShift))
        {
            playerPos = new Vector3(playerPos.x, playerPos.y - vertSpeed, playerPos.z);
        }
        // Get the vertical and horizontal input axes
        float verticalInput = Input.GetAxis("Vertical");
        float horizontalInput = Input.GetAxis("Horizontal");

        // Get the camera's forward and right vectors
        Vector3 cameraForward = Camera.main.transform.forward;
        Vector3 cameraRight = Camera.main.transform.right;

        // Calculate the movement direction relative to the camera's orientation
        Vector3 movementDirection = (cameraForward * verticalInput) + (cameraRight * horizontalInput);

        // Set the y component to 0 to restrict movement to the x-z plane
        movementDirection.y = 0f;

        // Normalize the vector to ensure consistent movement speed
        movementDirection.Normalize();

        //multiply by flightSpeed
        movementDirection *= flightSpeed;

        // Move the player in the calculated direction
        Vector3 translation = movementDirection * (vertSpeed * 40) * Time.fixedDeltaTime;

        playerPos += translation;

        if (!player)
            player = GetPlayerCharacter();
        player.transform.position = playerPos;
    }
    else if (!flight && player)
    {
        if (!player)
            player = GetPlayerCharacter();
        playerPos = player.transform.position;
    }
}