Untitled

mail@pastecode.io avatar
unknown
csharp
21 days ago
1.2 kB
4
Indexable
Never
private void HandleMovement()
    {
        dirX = Input.GetAxisRaw("Horizontal");
        dirY = Input.GetAxisRaw("Vertical");

        move = new Vector3(dirX, 0, dirY);
        move.Normalize();
        if(canMove)
        {
            controller.Move(move * Time.deltaTime * playerSpeed);
        }        
        if (!jumping && !isGrounded)
        {
            gravitationalMovement.x = 0;
            gravitationalMovement.y += gravitationValue * Time.deltaTime;
            gravitationalMovement.z = 0;
        }
        else
        {
            gravitationalMovement.y = 0f;
        }
        print(gravitationalMovement);
        controller.Move((gravitationalMovement + deltaMovement));
        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100, hitLayer))
        {
            mousePosition = new Vector3(hit.point.x, 0, hit.point.z);
        }
        if(canRotate)
        {
            Vector3 worldForward = transform.TransformPoint(Vector3.forward);
            transform.LookAt(Vector3.Lerp(worldForward,mousePosition + Vector3.up * transform.position.y, 0.1f));
        }
        deltaMovement = Vector3.zero;
    }
Leave a Comment