Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        mSteeringManager.ClearSteering();

        switch (mSettingsScript.getEnemyType())
        {
        case EnemySettings.enemyType.Seek:
        {
            mSteeringManager.Seek(mTarget.transform.position);
            mSteeringManager.wallAvoid(mTarget.transform.position);
            changeColour(Color.cyan);
            break;
        }

        case EnemySettings.enemyType.Flee:
        {
            mSteeringManager.Flee(mTarget.transform.position);
            changeColour(Color.green);
            break;
        }

        case EnemySettings.enemyType.Arrive:
        {
            mSteeringManager.Arrive(mTarget.transform.position);
            changeColour(Color.yellow);
            break;
        }

        case EnemySettings.enemyType.Pursue:
        {
            mSteeringManager.Pursue(mTarget.transform.position, mTarget.GetComponent <Rigidbody>().velocity);
            changeColour(Color.magenta);
            break;
        }

        case EnemySettings.enemyType.Evade:
        {
            mSteeringManager.Evade(mTarget.transform.position, mTarget.GetComponent <Rigidbody>().velocity);
            changeColour(Color.black);
            break;
        }

        case EnemySettings.enemyType.Wander:
        {
            mSteeringManager.Wander();
            mSteeringManager.Arrive(mTarget.transform.position);
            changeColour(Color.grey);
            break;
        }
        }

        Vector3 steering = mSteeringManager.getSteeringValue(mSettingsScript.getMaxForce());

        Vector3 velocityIn = mRigidBody.velocity;

        velocityIn.y = 0;

        Vector3 velocity = Vector3.ClampMagnitude(velocityIn + steering, mSettingsScript.getMaxSpeed());

        mRigidBody.velocity = velocity;


        checkState();
    }
Beispiel #2
0
    private void Locomotion()
    {
        velocity = manager.Truncate(velocity + steering, moveSpeed);

        //QBIT BEHAVIOR STATE MACHINE

        switch (actualstate)
        {
        case "WANDER":
            Vector3 wander = new Vector3(0.0f, 0.0f, 0.0f);
            if (Vector3.Distance(transform.position, home.transform.position) > homeradius)
            {
                Vector3 seek_wander = manager.Seek(transform.position, home.transform.position, moveSpeed);
                wander  = manager.Wander(transform.position, seek_wander, moveSpeed, VISIONANGLE, homeradius, displacementmargin);
                wander += velocity;
            }
            else
            {
                if (QBitController.velocity.magnitude > 0.1f)
                {
                    wander = manager.Wander(transform.position, pivot.transform.position, moveSpeed, VISIONANGLE, homeradius, displacementmargin);
                }
                else
                {
                    Vector3 flee_wander = manager.Flee(transform.position, pivot.transform.position, moveSpeed, homeradius);
                    wander = manager.Wander(transform.position, flee_wander, moveSpeed, VISIONANGLE, homeradius, displacementmargin);
                }
            }
            steering = wander;
            pivot.transform.position = steering;
            break;

        case "SEEK":
            if (Vector3.Distance(transform.position, objective.transform.position) > approachradius)
            {
                Vector3 seek = manager.Seek(transform.position, objective.transform.position, moveSpeed);
                steering = steering + seek;
            }
            else
            {
                Vector3 arrive = manager.Arrive(transform.position, objective.transform.position, runSpeed, approachradius);
                steering = velocity - arrive;
            }
            break;

        case "FLEE":
            Vector3 flee = manager.Flee(transform.position, objective.transform.position, moveSpeed, warningradius);
            if (QBitController.velocity.magnitude > 0.1f)
            {
                steering = (steering + flee) / 1.2f;
            }
            else
            {
                steering = flee;
            }
            break;

        case "STOP":
            steering.Set(0.0f, 0.0f, 0.0f);
            break;

        default:
            break;
        }

        //QBIT BEHAVIOR STATE MACHINE

        steering = new Vector3(steering.x, 0.0f, steering.z);

        //if (!QBitController.isGrounded)
        //{
        //    steering.y -= (GRAVITY * Time.deltaTime);
        //}
        steering = transform.TransformDirection(steering);
        QBitController.Move(steering * Time.fixedDeltaTime);
    }