コード例 #1
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        Vector2 direction = Target.getPosition() - Character.getPosition();
        float   distance  = direction.magnitude;

        float speed = Character.getVelocity().magnitude;

        float prediction;

        if (speed <= distance / maxPrediction)
        {
            prediction = maxPrediction;
        }
        else
        {
            prediction = distance / maxPrediction;
        }

        GameObject dummy      = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy"));
        AgentMeta  dummyAgent = dummy.GetComponent <AgentMeta> ();

        dummyAgent.setPosition(Target.getPosition() + Target.getVelocity() * prediction);

        Behaviour flee = new Flee(dummyAgent, Character);

        SteeringOutput.SteeringOutput steering = flee.getSteering();

        MonoBehaviour.Destroy(dummy);

        Behaviour lwyg = new LWYG(Character);

        steering += lwyg.getSteering();

        return(steering);
    }
コード例 #2
0
ファイル: Face.cs プロジェクト: marcosajc/IAJuegos-SD2017
    public override SteeringOutput.SteeringOutput getSteering()
    {
        SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(.0f, .0f), .0f);
        Vector2 dir = Target.getPosition() - Character.getPosition();

        if (dir.magnitude == 0)
        {
            return(steering);
        }
        Debug.Log(dir);

        GameObject dummy = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy"));
        AgentMeta  aux   = dummy.GetComponent <AgentMeta> ();

        aux.setPosition(Target.getPosition());
        aux.setOrientation(Mathf.Atan2(-dir.x, dir.y) * Mathf.Rad2Deg);
        Debug.Log(Mathf.Atan2(-dir.x, dir.y) * Mathf.Rad2Deg);
        Behaviour alinear = new Align(aux, Character, Mathf.PI / 10, Mathf.PI / 100, .1f);

        //steering.linear = steering.linear.normalized * Character.maxAcceleration;
        steering = alinear.getSteering();
        Debug.Log(steering.angular);
        MonoBehaviour.Destroy(dummy);
        return(steering);
    }
コード例 #3
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        GameObject dummy      = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy"));
        AgentMeta  dummyAgent = dummy.GetComponent <AgentMeta> ();

        if ((Character.getPosition() - path.Nodes[i]).magnitude < 1)
        {
            i++;
            if (path.Nodes.Count == i)
            {
                i = 0;
            }
            Debug.Log("NODE: " + path.Nodes [i].ToString());
        }

        dummyAgent.setPosition(path.Nodes[i]);
        //MonoBehaviour.print(dummyAgent.getPosition ());

        Behaviour seek = new ArriveWhileLooking(dummyAgent, Character, 1f, 0.5f, 0.1f);

        SteeringOutput.SteeringOutput steering = seek.getSteering();

        MonoBehaviour.Destroy(dummy);
        return(steering);
    }
コード例 #4
0
    public static void createProjectile(Vector3 vel, Vector3 pos)
    {
        GameObject dummy = (GameObject)ProyectilController.Instantiate(Resources.Load("Prefab/Ball2"));
        AgentMeta  am    = (AgentMeta)dummy.GetComponent <AgentMeta> ();

        am.setVelocity(vel);
        am.setPosition(pos);
    }
コード例 #5
0
    public override SteeringOutput.SteeringOutput getSteering()
    {
        wanderOrientation += base.randomBinomial() * wanderRate;
        //Debug.Log (wanderOrientation);

        float targetOrientation = wanderOrientation + Character.getOrientation();

        float targetOrientationRadian = targetOrientation * Mathf.Deg2Rad;
        float orientationRadian       = Character.getOrientation() * Mathf.Deg2Rad;
        //Debug.Log (targetOrientationRadian);
        //Debug.Log (targetOrientation);

        Vector2 target = Character.getPosition()
                         + wanderOffset * new Vector2(Mathf.Cos(orientationRadian), Mathf.Sin(orientationRadian)).normalized
                         + wanderRadius * new Vector2(Mathf.Cos(targetOrientationRadian), Mathf.Sin(targetOrientationRadian)).normalized;
        //Debug.Log (Mathf.Cos (180f * Mathf.Deg2Rad));
        //Debug.Log(new Vector2 (Mathf.Cos (targetOrientationRadian), Mathf.Sin (targetOrientationRadian)));

        //Debug.Log (target);

        GameObject dummy      = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy"));
        AgentMeta  dummyAgent = dummy.GetComponent <AgentMeta> ();

        dummyAgent.setPosition(target);
        dummyAgent.setOrientation(wanderOrientation + Character.getOrientation());
        //dummyAgent.setOrientation (

        //Debug.Log (dummyAgent.getPosition ()- Character.getPosition());

        //Behaviour face = new Face (dummyAgent, Character);
        //Debug.Log (dummyAgent.getPosition () - Character.getPosition());
        //Debug.Log (dummyAgent.getOrientation ());
        //Debug.Log (Character.getOrientation ());

        Behaviour seek = new SeekWhileLooking(dummyAgent, Character);

        //Behaviour lwyg = new LWYG (Character);

        //SteeringOutput.SteeringOutput steering = seek.getSteering () + lwyg.getSteering();
        SteeringOutput.SteeringOutput steering = seek.getSteering();
        Debug.Log(steering.angular);

        //steering.linear = Character.maxAcceleration * new Vector2 (Mathf.Cos (orientationRadian), Mathf.Sin (orientationRadian));

        MonoBehaviour.Destroy(dummy);
        return(steering);
    }
コード例 #6
0
	public override SteeringOutput.SteeringOutput getSteering() {

		Vector2 futurePos = Character.getPosition () + Character.getVelocity () * predictTime;

		currentParam = path.getParam (futurePos, currentParam);

		float targetParam = currentParam + PathOffset;

		GameObject dummy = (GameObject) MonoBehaviour.Instantiate (Resources.Load ("Prefab/Dummy"));
		AgentMeta dummyAgent = dummy.GetComponent<AgentMeta> ();
		dummyAgent.setPosition (path.getPosition (targetParam));

		Behaviour seek = new Seek (dummyAgent, Character);
		SteeringOutput.SteeringOutput steering = seek.getSteering ();

		MonoBehaviour.Destroy (dummy);
		return steering; 

	}
コード例 #7
0
ファイル: LWYG.cs プロジェクト: marcosajc/IAJuegos-SD2017
    public override SteeringOutput.SteeringOutput getSteering()
    {
        SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput();
        Vector2 velocity = Character.getVelocity();

        if (velocity.magnitude == 0)
        {
            return(steering);
        }

        GameObject dummy = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy"));
        AgentMeta  aux   = dummy.GetComponent <AgentMeta> ();

        aux.setPosition(new Vector2(0.0f, 0.0f));
        aux.setOrientation((Mathf.Atan2(-velocity.x, velocity.y) * Mathf.Rad2Deg) % 360.0f);
        Behaviour alinear = new Align(aux, Character, Mathf.PI / 100, Mathf.PI / 10, .1f);

        //steering.linear = steering.linear.normalized * Character.maxAcceleration;
        steering = alinear.getSteering();
        MonoBehaviour.Destroy(dummy);

        return(steering);
    }