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 seek = new Seek(dummyAgent, Character); SteeringOutput.SteeringOutput steering = seek.getSteering(); MonoBehaviour.Destroy(dummy); return(steering); }
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); }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(.0f, .0f), .0f); SteeringOutput.SteeringOutput auxSteering; for (int i = 0; i < weightedBehaviours.Count; i++) { auxSteering = weightedBehaviours [i].behaviour.getSteering(); auxSteering.linear.x *= weightedBehaviours [i].weight; auxSteering.linear.y *= weightedBehaviours [i].weight; auxSteering.angular *= weightedBehaviours [i].weight; steering += auxSteering; } Behaviour lwyg = new LWYG(Character); steering += lwyg.getSteering(); if (steering.linear.magnitude > Character.maxAcceleration) { steering.linear = steering.linear.normalized * Character.maxAcceleration; } if (steering.angular > Character.maxAngularAcceleration) { steering.angular = Character.maxAngularAcceleration; } return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { wanderOrientation = base.randomBinomial() * wanderRate; // Hallar Orientacion aleatoria float targetOrientation = Mathf.Abs(wanderOrientation + Character.orientation); // Obtener nueva orientacion objetivo. float targetOrientationRadian = targetOrientation * Mathf.Deg2Rad; // Orientacion en radianes float orientationRadian = Character.orientation * Mathf.Deg2Rad; Debug.Log("WO:" + wanderOrientation); Vector2 target = Character.position + wanderOffset * new Vector3(Mathf.Cos(orientationRadian), Mathf.Sin(orientationRadian), 0) + wanderRadius * new Vector3(Mathf.Cos(targetOrientationRadian), Mathf.Sin(targetOrientationRadian), 0); //GameObject dummy = (GameObject) MonoBehaviour.Instantiate (Resources.Load ("Prefab/Dummy")); AgentMeta dummyAgent = new AgentMeta(); // Agente auxiliar para cambiar orientacion. dummyAgent.position = target; dummyAgent.orientation = wanderOrientation + Character.orientation; /* Moverse en la direccion de la orientacion */ Behaviour face = new Face(dummyAgent, Character); SteeringOutput.SteeringOutput steering = face.getSteering(); steering.linear = Character.maxAcceleration * new Vector2(Mathf.Cos(orientationRadian), Mathf.Sin(orientationRadian)); /* Limpiar y salir */ MonoBehaviour.Destroy(dummyAgent); return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { Vector2 direction = Target.position - Character.position; float distance = direction.magnitude; float speed = Character.velocity.magnitude; float prediction; if (speed <= distance / maxPrediction) { prediction = maxPrediction; } else { prediction = distance / maxPrediction; } GameObject dummy = (GameObject)MonoBehaviour.Instantiate((GameObject)Resources.Load("Prefab/Dummy")); AgentMeta dummyAgent = dummy.GetComponent <AgentMeta> (); dummyAgent.position = Target.position + Target.velocity * prediction; Behaviour flee = new Flee(dummyAgent, Character); SteeringOutput.SteeringOutput steering = flee.getSteering(); MonoBehaviour.Destroy(dummy); return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(0.0f, 0.0f), 0.0f); Vector2 direction = Target.getPosition() - Character.getPosition(); float distance = direction.magnitude; if (distance < targetRadius) { return(steering); } var targetSpeed = Character.maxSpeed; if (distance <= slowRadius) { targetSpeed *= distance / slowRadius; } var targetVelocity = direction.normalized * targetSpeed; steering.linear = targetVelocity - Character.getVelocity(); steering.linear /= timeToTarget; steering.angular = 0.0f; Behaviour lwyg = new LWYG(Character); steering += lwyg.getSteering(); return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(0.0f, 0.0f), 0.0f); float rotation = Character.getOrientation() - Target.getOrientation(); // Diferencia en las orientaciones rotation *= Mathf.Deg2Rad - Mathf.PI; // Mapping float rotationSize = Mathf.Abs(rotation); // Diferencia en las orientaciones (Solo magnitud). bool cond1 = rotationSize < targetRadius; if (cond1) // Si la diferencia es muy pequenia, chao. { Character.setRotation(0f); return(steering); } /* Calculo de aceleracion */ float targetRotation = Character.maxRotation; // Velocidad de rotacion maxima. (Fuera del radio) if (rotationSize <= slowRadius) // Si estoy acercandome, disminuir aceleracion { targetRotation *= rotationSize / slowRadius; } targetRotation *= rotation / rotationSize; steering.angular = targetRotation - Character.getRotation(); steering.angular /= timeToTarget; return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { Vector2 direction = Target.getPosition() - Character.getPosition(); float distance = direction.sqrMagnitude; float speed = Character.getVelocity().sqrMagnitude; float prediction; if (speed <= distance / maxPrediction) { prediction = maxPrediction; } else { prediction = distance / maxPrediction; } AgentMeta dummy = new AgentMeta(new Vector2(0.0f, 0.0f) + Target.getVelocity() * prediction); Behaviour seek = new Seek(dummy, Character); SteeringOutput.SteeringOutput steering = seek.getSteering(); return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(); steering.linear = Character.position - Target.position; steering.linear = steering.linear.normalized * Character.maxAcceleration; steering.angular = 0.0f; return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { Behaviour seek = new Seek(Target, Character); Behaviour lwyg = new LWYG(Character); SteeringOutput.SteeringOutput steering = lwyg.getSteering() + seek.getSteering(); return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(); steering.linear = Target.getVelocity() - Character.getVelocity(); steering.linear /= Character.maxAcceleration; steering.angular = 0.0f; return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(0.0f, 0.0f), 0.0f); float shortestTime = float.MaxValue; // Tiempo faltante para la colision. AgentMeta firstTarget = null; // Agente mas cercano a ocasionar una colision. // Distancias y posiciones relativas entre agentes. float firstMinSeparation = -1, firstDistance = float.MaxValue; Vector2 firstRelativePos = new Vector2(), firstRelativeVel = new Vector2(), relativePos; foreach (AgentMeta target in targets) // Para cada objeto que puede causar una colision. { relativePos = target.position - Character.position; // Posicion de Agente -> Target Vector2 relativeVel = target.velocity - Character.velocity; // Velocidad Agente -> Target. float relativeSpeed = relativeVel.magnitude; // Rapidez relativa. float distance = relativePos.magnitude; // Distancia relativa entre agentes. float minSeparation = distance - relativeSpeed * shortestTime; // Separacion minima (COLISION). /* Proyeccion del vector posicion sobre el vector velocidad para estimar el tiempo de colision. */ float timeToCollision = Mathf.Abs(Vector2.Dot(relativePos, relativeVel) / (relativeSpeed * relativeSpeed)); if (minSeparation > 2 * radius) { continue; } if (timeToCollision > 0 && timeToCollision < shortestTime) { /* Actualizacion del objetivo mas proximo a ocasionar colision */ shortestTime = timeToCollision; Debug.Log("ShortT: " + shortestTime); firstTarget = target; firstMinSeparation = minSeparation; firstDistance = distance; firstRelativePos = relativePos; firstRelativeVel = relativeVel; } } /* Realizar evasion */ if (firstTarget != null) { if (firstMinSeparation <= 0 || firstDistance < 2 * radius) { /* Caso 1: Ya choque, que chimbo */ relativePos = firstTarget.position - Character.position; } else { /* Caso 2: Si sigo asi voy a chocar, y eso no es bueno :( */ relativePos = firstRelativePos + firstRelativeVel * shortestTime; } relativePos.Normalize(); steering.linear = -relativePos * maxAcc; } return(steering); }
// Update is called once per frame void Update() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(); currentBehaviour = ListBehaviours [Player.getCurrentBehaviour() % ListBehaviours.Count]; print(currentBehaviour.getBehaviourName()); //print (this.position); steering = currentBehaviour.getSteering(); this.linear = steering.linear; this.angular = steering.angular; }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(); steering.linear = Character.getPosition() - Target.getPosition(); steering.linear = steering.linear.normalized * Character.maxAcceleration; steering.angular = 0.0f; Behaviour lwyg = new LWYG(Character); steering += lwyg.getSteering(); return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(.0f, .0f), .0f); for (int i = 0; i < groups.Count; i++) { steering = groups [i].getSteering(); if (steering.linear.magnitude > epsilon || Mathf.Abs(steering.angular) > epsilon) { return(steering); } } return(steering); }
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); }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(0.0f, 0.0f), 0.0f); Behaviour selectedBehaviour; float orientationDiff = Mathf.Abs(Target.orientation - Character.orientation - 180f); if (orientationDiff < stalkRadius) { selectedBehaviour = new FleeWhileLooking(Target, Character); } else { selectedBehaviour = new ArriveWhileLooking(Target, Character, 3f, 1f, .1f); } steering = selectedBehaviour.getSteering(); return(steering); }
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; }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(0.0f, 0.0f), 0.0f); Behaviour selectedBehaviour; float distance = (Target.getPosition() - Character.getPosition()).magnitude; if (distance < pokeDistance) { selectedBehaviour = new Flee(Target, Character); } else { selectedBehaviour = new SeekWhileLooking(Target, Character); } steering = selectedBehaviour.getSteering(); return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { /* Calcular direccion y magnitud del cono */ float angle = Character.orientation; Vector3 orientation = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0f); GameObject obstacle = GameObject.Find("Obstacle_1"); ObstacleCreator oc = obstacle.GetComponent <ObstacleCreator> (); Vector3 startPos = Character.transform.position; startPos.z = -1; Vector3 endPos = startPos + orientation.normalized * Character.viewRadius; endPos.z = -1; bool choca = oc.bbx.rayCollides(startPos, endPos); foreach (Vector2 v in oc.bbx.vertex) { if ((startPos - new Vector3(v.x, v.y)).magnitude < Character.viewRadius && Vector3.Angle(startPos, v) <= Character.viewAngle) { choca = true; break; } } Debug.Log("BOOL: " + choca.ToString() + "positions" + startPos + endPos); /* Pintar perolito*/ SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(new Vector2(0.0f, 0.0f), 0.0f); if (choca) { steering.linear = new Vector2(orientation.y, -orientation.x).normalized *Character.maxAcceleration; Character.lineRender.material.color = Color.red; Character.lineRender.startColor = Color.red; Character.lineRender.endColor = Color.red; } else { Character.lineRender.material.color = Color.green; Character.lineRender.startColor = Color.green; Character.lineRender.endColor = Color.green; } Vector3[] linePositions = { startPos, endPos }; Character.lineRender.SetPositions(linePositions); return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(); Vector2 dir = Target.position - Character.position; if (dir.magnitude == 0) { return(steering); } GameObject dummy = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy")); AgentMeta aux = dummy.GetComponent <AgentMeta> (); aux.position = Target.position; aux.orientation = Mathf.Atan2(-dir.x, dir.y) * Mathf.Rad2Deg; Behaviour alinear = new Align(aux, Character, Mathf.PI / 4, Mathf.PI / 10, .1f); //steering.linear = steering.linear.normalized * Character.maxAcceleration; steering = alinear.getSteering(); MonoBehaviour.Destroy(dummy); return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { float strength = 0; SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(); foreach (AgentMeta target in Targets) { Vector2 direction = -target.position + Character.position; float distance = direction.magnitude; if (distance < Threshold && distance != 0) { strength = Decay / (distance * distance); direction.Normalize(); steering.linear += strength * direction; } else { steering.linear = -Character.maxAcceleration * direction.normalized; } } return(steering); }
public override SteeringOutput.SteeringOutput getSteering() { SteeringOutput.SteeringOutput steering = new SteeringOutput.SteeringOutput(); Vector2 velocity = Character.velocity; if (velocity.magnitude == 0) { return(steering); } GameObject dummy = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Prefab/Dummy")); AgentMeta aux = dummy.GetComponent <AgentMeta> (); aux.position = new Vector2(0.0f, 0.0f); aux.orientation = (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); }