Пример #1
0
    void Update()
    {
        input = Camera.main.transform.root.TransformDirection(new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")));
        if (input.magnitude > 1f)
        {
            input = input.normalized;
        }
        input     *= moveSpeed;
        isGrounded = GroundCheck();
        if (Input.GetButtonDown("Jump"))
        {
            Jump();
        }
        if (!isGrounded)
        {
            velocity.y += gravity * Time.deltaTime;
        }
        if (Input.GetButtonUp("Jump") && velocity.y > minJumpVelocity)
        {
            velocity.y = minJumpVelocity;
        }
        input.y = velocity.y;
        transform.LookAt(new Vector3(transform.position.x + velocity.x, transform.position.y, transform.position.z + velocity.z));
        if (pc.isGrounded)
        {
            wasGrounded = true;
        }
        else
        {
            wasGrounded = false;
        }
        float smoothMod = smooth;

        if (!isGrounded)
        {
            smoothMod = airSmooth;
        }
        if (!Input.GetButton("Jump") && Vector3.Angle(normal, Vector3.up) > pc.slopeLimit && isGrounded)
        {
            Vector3 cross     = Vector3.Cross(normal, Vector3.up).normalized;
            Vector3 flatInput = new Vector3(input.x, 0, input.z);
            if (Vector3.Angle(cross, input) > 90)
            {
                cross *= -1;
            }
            Vector3 tempX = cross * (flatInput.magnitude * Mathf.Cos(Vector3.Angle(flatInput, cross) * Mathf.Deg2Rad));
            input = tempX + Quaternion.AngleAxis(-90, Vector3.Cross(normal, Vector3.up)) * normal * moveSpeed;
            Debug.DrawLine(transform.position, transform.position + input, Color.red, 100);
        }
        velocity = Vector3.SmoothDamp(velocity, input, ref smoothdamp, smoothMod);
        pc.Move(velocity * Time.deltaTime);
        if (timeToWallUnstick > 0)
        {
            timeToWallUnstick -= Time.deltaTime;
        }
        else
        {
            timeToWallUnstick = 0;
        }

        if (pc.isGrounded && !wasGrounded)
        {
            pe.Land();
        }
    }