SHR_Waypoint wp => (SHR_Waypoint)target;  //are we using the Inspector to look at a Waypoint?

    public void SnapToGround()
    {
        var hitResult = RayCollider.Raycast(wp.transform.position, Vector3.down, 100);

        if (hitResult.AnyGround)
        {
            wp.transform.position = hitResult.hit.point;
        }
    }
Beispiel #2
0
        void Rule_Climbing()
        {
            #region Rule
            if (newRule)
            {
                velXZ = Vector3.zero;
                velY  = 0;
                anim.Set(Anim.ClimbWallStart, 1);

                if (col.wall.hit.normal != Vector3.zero && Mathf.Abs(col.wall.hit.normal.y) < 0.707f)
                {
                    pos = col.wall.hit.point + col.wall.hit.normal * 0.5f;
                }
                colClimb = col.wall;
            }

            if ((colClimb = RayCollider.Raycast(pos + colClimb.hit.normal, -colClimb.hit.normal, 3)).ClimbableWall && Mathf.Abs(colClimb.hit.normal.y) < 0.707f)
            {
                LookAt(pos - colClimb.hit.normal);
                pos = colClimb.hit.point + colClimb.hit.normal * 0.5f;
                if (lStick.magnitude > deadZone)
                {
                    pos += matRot.MultiplyVector(lStick_s) * 6 * dt;
                }
            }

            else if (apprVel.y > 2 && lStickAngle * Mathf.Sign(lStickAngle) < 30)
            {
                Jump(4, false);
            }

            col.wallEnabled = false;
            #endregion
            #region Animation
            float la = 0;
            if (lStick_s.magnitude > deadZone)
            {
                la = lStickAngle;
                anim.SetSpeed(lStick_s.magnitude * 35);
                if (la > -45 && la < 45)
                {
                    anim.Set(Anim.ClimbWallUpStart, 1);
                }
                else if (la >= 45 && la <= 135)
                {
                    anim.Set(Anim.ClimbWallRightStart, 1);
                }
                else if (la > 135 || la < -135)
                {
                    anim.Set(Anim.ClimbWallDownStart, 1);
                }
                else if (la >= -135 && la <= -45)
                {
                    anim.Set(Anim.ClimbWallLeftStart, 1);
                }
            }
            else
            {
                anim.SetSpeed(25);
                if (la > -45 && la < 45)
                {
                    anim.Set(Anim.ClimbWallUpEnd, 1);
                }
                else if (la > 45 && la < 135)
                {
                    anim.Set(Anim.ClimbWallRightEnd, 1);
                }
                else if (la > 135 || la < -135)
                {
                    anim.Set(Anim.ClimbWallDownEnd, 1);
                }
                else if (la > -135 && la < -45)
                {
                    anim.Set(Anim.ClimbWallLeftEnd, 1);
                }
            }
            #endregion
        }
Beispiel #3
0
        void Rule_Air()
        {
            #region Rule
            col.groundDepth = 0;
            col.UpdateGroundCollision();

            if (newRule)
            {
                liftOffVel = velXZ.magnitude;
            }

            if (col.ground.AnyGround && velY <= 0)
            {
                velY = 0;
                SetRule("Ground");
                return;
            }
            else if (col.ground.Slide)
            {
                SetRule("Sliding");
                return;
            }
            else if (col.ground.Water && velY < 0 && !col.waterIsShallow)
            {
                SetRule("Swimming");
                return;
            }
            else if (!t_blockHang.active && col.ceiling.HangableCeiling)
            {
                SetRule("Hanging");
                return;
            }

            if (jumping)
            {
                gravity = -20;
                if (velY < jumpCutoff)
                {
                    jumping = false;
                }
            }
            else
            {
                gravity = -30;
            }


            // Ledgegrab
            var lh = Raycast(forward * 2 + upward * 3, -upward, 1);
            if (lh.AnyGround)
            {
                float       dist  = DistTo(lh);
                CollideInfo ledge = new CollideInfo();
                for (float d = dist; d > 0; d -= 0.05f)
                {
                    var lh2 = RayCollider.Raycast(pos + d * Vec2D(pos, lh.hit.point), -upward, 2);
                    if (!lh2.AnyGround)
                    {
                        ledge = lh2;
                        break;
                    }
                }
                if (ledge.AnyGround)
                {
                    this.ledge = ledge;
                    SetRule("Ledgegrab");
                    return;
                }
            }


            ApplyGravity();

            if (helic)
            {
                if (superHelicAscend)
                {
                    superHelicRev = Mathf.Lerp(superHelicRev, 42, dt * 45);
                }
                else
                {
                    superHelicRev = Mathf.Lerp(superHelicRev, 0, dt * 1);
                }

                SFX("Rayman2/Rayman/helic").asrc.pitch = 1 + superHelicRev / 300;
                anim.SetSpeed(30 + superHelicRev / 7);

                SetFriction(6.5f, hasSuperHelic ? 2.6f : 7.5f);
                velY    += dt * superHelicRev;
                velY     = Mathf.Clamp(velY, hasSuperHelic ? -25 : -5, 5);
                selfJump = false;
            }
            else
            {
                if (slideJump)
                {
                    SetFriction(0.1f, 0);
                }
                else
                {
                    SetFriction(5, 0);
                }
                moveSpeed = 10;
            }


            MoveOrStrafe(6, helic ? 5 : -1);
            AlignY(10);

            if (pos.y < startPos.y - 1100)
            {
                SetRule("Falling");
            }
            #endregion
            #region Animation
            if (helic)
            {
                anim.Set(Anim.HelicEnable, 1);
            }
            else if (liftOffVel < 5 || !selfJump)
            {
                if (velY > 5 + jumpLiftOffVelY)
                {
                    anim.Set(Anim.JumpIdleLoop, 0);
                }
                else
                {
                    if (newRule)
                    {
                        anim.Set(Anim.FallIdleLoop, 0);
                    }
                    else
                    {
                        anim.Set(Anim.FallIdleStart, 1);
                    }
                }
            }
            else
            {
                if (velY > 5 + jumpLiftOffVelY)
                {
                    anim.Set(Anim.JumpRunLoop, 0);
                }
                else
                {
                    if (newRule)
                    {
                        anim.Set(Anim.FallRunLoop, 0);
                    }
                    else
                    {
                        anim.Set(Anim.FallRunStart, 1);
                    }
                }
            }
            #endregion
        }