Esempio n. 1
0
 // Use this for initialization
 void Start()
 {
     aligned    = new Align();
     looky      = new Look_Where_Going();
     facing     = new Face();
     pathFollow = new Path_Follow();
     seeking    = new Seek_And_Flee();
     separate   = new Separation();
     pursuing   = new Pursue();
     avoid      = new CollisionAvoidance();
     obstacles  = new Obstacle_Avoidance();
 }
    // Use this for initialization
    void Start()
    {
        arrive     = new Arrival();
        aligned    = new Align();
        looky      = new Look_Where_Going();
        facing     = new Face();
        pathFollow = new Path_Follow();
        seeking    = new Seek_And_Flee();
        separate   = new Separation();
        pursuing   = new Pursue();
        avoid      = new CollisionAvoidance();
        obstacles  = new Obstacle_Avoidance();
        flocking   = new Blended_Steering();

        behaviors = new BehaviorAndWeight[4];
    }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        arrive     = new Arrival();
        aligned    = new Align();
        looky      = new Look_Where_Going();
        facing     = new Face();
        pathFollow = new Path_Follow();
        seeking    = new Seek_And_Flee();
        separate   = new Separation();
        pursuing   = new Pursue();
        avoid      = new CollisionAvoidance();
        obstacles  = new Obstacle_Avoidance();
        flocking   = new Blended_Steering();
        //finding = new Pathfinder();

        behaviors = new BehaviorAndWeight[4];

        // Use if doing Path Finding:
        //Graph myGraph = new Graph();

        //myGraph.Build();

        //List<Connection> path = Dijkstra.pathfind(myGraph, start, goal);

        //// path is a list of connections - convert this to gameobjects for the FollowPath steering behavior

        //aiTargets = new GameObject[path.Count + 1];

        //int i = 0;

        //foreach (Connection c in path)

        //{

        //    Debug.Log("from " + c.getFromNode() + " to " + c.getToNode() + " @" + c.getCost());

        //    aiTargets[i] = c.getFromNode().gameObject;

        //    i++;

        //}

        //aiTargets[i] = goal.gameObject;
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        seeking = new Seek_And_Flee();
        arrive  = new Arrival();
        //aligning = new Align();

        SteeringOutput moving  = new SteeringOutput();
        SteeringOutput turning = new SteeringOutput();

        seeking.character = this;
        seeking.target    = aiTarget;

        arrive.character = this;
        arrive.target    = aiTarget;

        SteeringOutput movement = new SteeringOutput();

        switch (movementType)
        {
        case "Seek":
            moving = seeking.GetSteering();

            if (moving == null)
            {
                movement.linear = Vector3.zero;
            }
            else
            {
                movement.linear  = moving.linear;
                movement.angular = turning.angular;
            }

            break;

        case "Flee":
            flee = true;

            moving = seeking.GetSteering();

            if (moving == null)
            {
                movement.linear = Vector3.zero;
            }
            else
            {
                movement.linear  = moving.linear;
                movement.angular = turning.angular;
            }

            break;

        case "Arrive":
            moving = arrive.GetSteering();

            if (moving == null)
            {
                movement.linear = Vector3.zero;
            }
            else
            {
                movement.linear  = moving.linear;
                movement.angular = turning.angular;
            }

            break;

        case "Face":
            Face staticFace = new Face();

            staticFace.target    = aiTarget;
            staticFace.character = this;

            //moving = seeking.GetSteering();
            turning = staticFace.GetSteering();

            movement.linear  = Vector3.zero;
            movement.angular = turning.angular;

            break;

        case "Seek Align":
            Align          aligning = new Align();
            SteeringOutput turn     = new SteeringOutput();

            aligning.character = this;
            aligning.target    = aiTarget;

            moving = seeking.GetSteering();
            turn   = aligning.GetSteering();

            movement.linear  = moving.linear;
            movement.angular = turn.angular;

            break;

        case "Seek Face":
            Face faces = new Face
            {
                character = this,
                target    = aiTarget
            };

            moving  = seeking.GetSteering();
            turning = faces.GetSteering();

            if (moving == null)
            {
                movement.linear = Vector3.zero;
            }
            else
            {
                movement.linear  = moving.linear;
                movement.angular = turning.angular;
            }

            break;

        case "Seek Look":
            Look_Where_Going looky      = new Look_Where_Going();
            SteeringOutput   shouldTurn = new SteeringOutput();

            looky.character = this;
            looky.target    = aiTarget;

            Debug.Log(looky.GetSteering());

            moving     = seeking.GetSteering();
            shouldTurn = looky.GetSteering();

            Debug.Log(looky.GetSteering());

            movement.linear  = moving.linear;
            movement.angular = shouldTurn.angular;

            break;

        case "Arrive Align":
            Align aligned = new Align
            {
                character = this,
                target    = aiTarget
            };

            moving  = arrive.GetSteering();
            turning = aligned.GetSteering();

            if (moving == null)
            {
                movement.linear = Vector3.zero;
            }
            else
            {
                movement.linear  = moving.linear;
                movement.angular = turning.angular;
            }

            break;

        case "Arrive Face":
            Face facing = new Face();

            facing.character = this;
            facing.target    = aiTarget;

            //Debug.Log(facing.target);
            //Debug.Log(facing);

            moving  = arrive.GetSteering();
            turning = facing.GetSteering();

            //Debug.Log(facing);
            //Debug.Log(turning.angular);

            movement.linear  = moving.linear;
            movement.angular = turning.angular;

            //Debug.Log(movement.angular);

            break;

        case "Arrive Look":
            Look_Where_Going look = new Look_Where_Going
            {
                character = this,
                target    = aiTarget
            };

            moving  = arrive.GetSteering();
            turning = look.GetSteering();

            //Debug.Log(turning.angular);

            movement.linear  = moving.linear;
            movement.angular = turning.angular;

            Debug.Log(movement.angular);

            break;

        default:
            Face aligns = new Face
            {
                character = this,
                target    = aiTarget
            };

            moving  = seeking.GetSteering();
            turning = aligns.GetSteering();

            if (moving == null)
            {
                movement.linear = Vector3.zero;
            }
            else
            {
                movement.linear  = moving.linear;
                movement.angular = turning.angular;
            }

            break;
        }

        // Update linear and angular velocities

        //Debug.Log(movement.angular);

        linearVel  += movement.linear * Time.deltaTime;
        angularVel += movement.angular * Time.deltaTime;

        //angularInc *= Mathf.Rad2Deg;

        transform.position += linearVel * Time.deltaTime;
        angularInc          = new Vector3(0, angularVel * Time.deltaTime, 0);
        //Debug.Log(angularInc);

        transform.eulerAngles += angularInc;
    }