コード例 #1
0
    /// enters wallrunnign against a wall.
    /// We save the wallrun hit info so we dont wallrun twice into the
    /// same wall without touching ground
    private void EnterWallrunning(WallrunHit wallrunHit)
    {
        if (wallrunHit.obj == lastWallrunHit.obj)
        {
            return;
        }

        this.State = PlayerState.wallrunning;
        Vector3 currentVelocity = this.rigidBody.velocity;

        this.rigidBody.velocity = new Vector3(currentVelocity.x, 6.2f, currentVelocity.z);
        this.camera.AnimateEnterWallrun(wallrunHit.isRight);

        LeanTween.rotate(this.gameObject, Quaternion.LookRotation(wallrunHit.moveVector, Vector3.up).eulerAngles, 0.3f);

        this.currentGravity = wallrunGravity;
        lastWallrunHit      = wallrunHit;
    }
コード例 #2
0
    /// Uses raycasts to check wether we should enter wall run
    private bool CheckWallrun(out WallrunHit hitObject)
    {
        RaycastHit hit;

        Debug.DrawRay(feet.position, this.transform.rotation * Vector3.left * wallrunCheckerDistance, Color.green);
        Debug.DrawRay(feet.position, this.transform.rotation * Vector3.right * wallrunCheckerDistance, Color.cyan);

        if (Physics.Raycast(feet.position, this.transform.rotation * Vector3.left, out hit, wallrunCheckerDistance, LayerMask.GetMask("Wall")))
        {
            hitObject = new WallrunHit {
                obj          = hit.transform.gameObject,
                isRight      = false,
                moveVector   = Quaternion.Euler(0, -90f, 0) * hit.normal,
                normalVector = hit.normal,
            };

            return(true);
        }


        if (Physics.Raycast(feet.position, this.transform.rotation * Vector3.right, out hit, wallrunCheckerDistance, LayerMask.GetMask("Wall")))
        {
            hitObject = new WallrunHit {
                obj          = hit.transform.gameObject,
                isRight      = true,
                moveVector   = Quaternion.Euler(0, 90f, 0) * hit.normal,
                normalVector = hit.normal,
            };
            return(true);
        }


        hitObject = new WallrunHit {
        };
        return(false);
    }