예제 #1
0
    public void UpdateMovement(float delta)
    {
        float num = WaterFactor();

        if (num > 1f && !base.IsDestroyed)
        {
            Kill();
            return;
        }
        if (desiredRotation != 0f)
        {
            MarkObstacleDistanceDirty();
        }
        if (num >= 0.3f && currentRunState > RunState.run)
        {
            currentRunState = RunState.run;
        }
        else if (num >= 0.45f && currentRunState > RunState.walk)
        {
            currentRunState = RunState.walk;
        }
        if (UnityEngine.Time.time - lastInputTime > 3f && !IsLeading())
        {
            currentRunState = RunState.stopped;
            desiredRotation = 0f;
        }
        if ((HasDriver() && IsLeading()) || leadTarget == null)
        {
            SetLeading(null);
        }
        if (IsLeading())
        {
            Vector3 position = leadTarget.transform.position;
            Vector3 lhs      = Vector3Ex.Direction2D(base.transform.position + base.transform.right * 1f, base.transform.position);
            Vector3 lhs2     = Vector3Ex.Direction2D(base.transform.position + base.transform.forward * 0.01f, base.transform.position);
            Vector3 rhs      = Vector3Ex.Direction2D(position, base.transform.position);
            float   value    = Vector3.Dot(lhs, rhs);
            float   num2     = Vector3.Dot(lhs2, rhs);
            bool    flag     = Vector3Ex.Distance2D(position, base.transform.position) > 2.5f;
            bool    num3     = Vector3Ex.Distance2D(position, base.transform.position) > 10f;
            if (flag || num2 < 0.95f)
            {
                float num4 = Mathf.InverseLerp(0f, 1f, value);
                float num5 = 1f - Mathf.InverseLerp(-1f, 0f, value);
                desiredRotation  = 0f;
                desiredRotation += num4 * 1f;
                desiredRotation += num5 * -1f;
                if (Mathf.Abs(desiredRotation) < 0.001f)
                {
                    desiredRotation = 0f;
                }
                if (flag)
                {
                    SwitchMoveState(RunState.walk);
                }
                else
                {
                    SwitchMoveState(RunState.stopped);
                }
            }
            else
            {
                desiredRotation = 0f;
                SwitchMoveState(RunState.stopped);
            }
            if (num3)
            {
                SetLeading(null);
                SwitchMoveState(RunState.stopped);
            }
        }
        float    obstacleDistance = GetObstacleDistance();
        RunState runState         = StateFromSpeed(obstacleDistance * GetRunSpeed());

        if (runState < currentRunState)
        {
            SwitchMoveState(runState);
        }
        float   desiredVelocity = GetDesiredVelocity();
        Vector3 direction       = Vector3.forward * Mathf.Sign(desiredVelocity);
        float   num6            = Mathf.InverseLerp(0.85f, 1f, obstacleDistance);
        float   num7            = Mathf.InverseLerp(1.25f, 10f, obstacleDistance);
        float   num8            = 1f - Mathf.InverseLerp(20f, 45f, Vector3.Angle(Vector3.up, averagedUp));

        num7 = num6 * 0.1f + num7 * 0.9f;
        float num9  = Mathf.Min(Mathf.Clamp01(Mathf.Min(num8 + 0.2f, num7)) * GetRunSpeed(), desiredVelocity);
        float num10 = ((num9 < currentSpeed) ? 3f : 1f);

        if (Mathf.Abs(currentSpeed) < 2f && desiredVelocity == 0f)
        {
            currentSpeed = Mathf.MoveTowards(currentSpeed, 0f, delta * 3f);
        }
        else
        {
            currentSpeed = Mathf.Lerp(currentSpeed, num9, delta * num10);
        }
        if (num7 == 0f)
        {
            currentSpeed = 0f;
        }
        float num11 = 1f - Mathf.InverseLerp(2f, 7f, currentSpeed);

        num11 = (num11 + 1f) / 2f;
        if (desiredRotation != 0f)
        {
            Vector3    position2 = animalFront.transform.position;
            Quaternion rotation  = base.transform.rotation;
            base.transform.Rotate(Vector3.up, desiredRotation * delta * turnSpeed * num11);
            if (!IsLeading() && Vis.AnyColliders(animalFront.transform.position, obstacleDetectionRadius * 0.25f, 1503731969))
            {
                base.transform.rotation = rotation;
            }
        }
        Vector3 vector     = base.transform.TransformDirection(direction);
        Vector3 normalized = vector.normalized;
        float   num12      = currentSpeed * delta;
        Vector3 vector2    = base.transform.position + normalized * num12 * Mathf.Sign(currentSpeed);

        currentVelocity = vector * currentSpeed;
        UpdateGroundNormal();
        if (!(currentSpeed > 0f) && !(timeAlive < 2f) && !((float)dropUntilTime > 0f))
        {
            return;
        }
        Vector3    vector3 = base.transform.position + base.transform.InverseTransformPoint(animalFront.transform.position).y *base.transform.up;
        RaycastHit hitInfo;
        bool       flag2 = UnityEngine.Physics.SphereCast(animalFront.transform.position, obstacleDetectionRadius, normalized, out hitInfo, num12, 1503731969);
        bool       flag3 = UnityEngine.Physics.SphereCast(base.transform.position + base.transform.InverseTransformPoint(animalFront.transform.position).y *base.transform.up, obstacleDetectionRadius, normalized, out hitInfo, num12, 1503731969);

        if (!Vis.AnyColliders(animalFront.transform.position + normalized * num12, obstacleDetectionRadius, 1503731969) && !flag2 && !flag3)
        {
            if (DropToGround(vector2 + Vector3.up * maxStepHeight))
            {
                MarkDistanceTravelled(num12);
            }
            else
            {
                currentSpeed = 0f;
            }
        }
        else
        {
            currentSpeed = 0f;
        }
    }