//float orientation; public override Steering getSteering(AgenteNPC agente) { Steering steering = new Steering(0, new Vector3(0, 0, 0)); wanderOrientation += Random.Range(-1, 1) * wanderRate; float targetOrientation; targetOrientation = wanderOrientation + agente.orientation; Vector3 centro; centro = agente.position + wanderOffset * Cuerpo.orientationToVector(agente.orientation); centro += wanderRadius * orientationAsVector(targetOrientation); target = new Agente(centro); steering = base.getSteering(agente); steering.linear = agente.maxAcceleration * Cuerpo.orientationToVector(agente.orientation); return(steering); }
public Steering getSteering(AgenteNPC agente) { // AÑADIDO PARA EL GRID /*if (path == null) * return new Steering(0,agente.getPosition());*/ setPath(agente); if (path == null) { return(new Steering(0, Vector3.zero)); } // TO DO, REINICIAR CURRENT NODE A 0 Waypoint targetPoint = path.getPosition(currentNode); int pathLength = path.getLength(); if (Vector3.Distance(agente.transform.position, targetPoint.getPosition()) <= targetPoint.getRadius()) { currentNode += pathDir; } // Opcion 1. Para llegado al último punto del camino if (currentNode >= pathLength) { currentNode = pathLength - 1; } target = targetPoint; return(base.getSteering(agente)); }
public Steering getSteering(AgenteNPC agente) { Steering steering = new Steering(0, new Vector3(0, 0, 0)); float rotacion = 0; if (agente.getOrientation() > 3.14f) { rotacion = 6.28f - agente.getOrientation() + target.getOrientation() - Mathf.PI; } else { rotacion = target.orientation - agente.orientation; } float rotationSize = Mathf.Abs(rotacion); if (rotationSize > target.exteriorAngle) { targetRotation = agente.maxRotation; } else if (rotationSize > target.interiorAngle) { targetRotation = agente.maxRotation * rotacion / rotationSize; } targetRotation *= rotacion / rotationSize; steering.angular = targetRotation - agente.rotation; steering.angular /= timeToTarget; return(steering); }
public override Steering getSteering(AgenteNPC agente) { int count = 0; float distance; float orientacion = Cuerpo.positionToAngle(Vector3.zero); float direction = 1; float alpha; foreach (Agente t in targets) { distance = (t.getPosition() - agente.getPosition()).magnitude; if (distance > threshold) { continue; } orientacion += t.getOrientation(); count++; } if (count > 0) { orientacion /= count; orientacion -= agente.getOrientation(); } return(new Steering(orientacion, Vector3.zero)); }
public Steering getSteering(AgenteNPC agente) { int count = 0; Vector3 centerOfMass = Vector2.zero; Vector3 direction; float distance; foreach (Agente t in targets) { direction = t.getPosition() - agente.getPosition(); distance = Vector3.Magnitude(direction); if (distance > threshold) { continue; } centerOfMass += t.getPosition(); count++; } if (count == 0) { return(null); } centerOfMass /= count; target = new Agente(centerOfMass); return(base.getSteering(agente)); }
public Steering getSteering(AgenteNPC agente) { Vector3 lineal = (target.getPosition() - agente.transform.position).normalized; lineal *= agente.maxAcceleration; lineal -= agente.velocity; return(new Steering(0, lineal)); }
public void setPath(AgenteNPC agente) { if (path != null) { if (currentNode > path.getLength()) { currentNode = 0; } } path = agente.getPath(); }
public override Steering getSteering(AgenteNPC agente) { // Inicializo el detector de colisiones cd = new CollisionDetector(); // Calculo el rayo del vector de colision Vector3 targetPosition = targetWallAvoidance.getPosition(); // Vector3 que representan los "bigotes" que buscaran colisiones //rayVector = agente.getVelocity().normalized; rayVector = (targetPosition - agente.getPosition()).normalized; //float angle = Cuerpo.positionToAngle(agente.getPosition()); float angle = positionToAngle(rayVector); rayVectorL = orientationToVector(angle + anguloApertura * Mathf.Deg2Rad); rayVectorR = orientationToVector(angle - anguloApertura * Mathf.Deg2Rad); rayVector *= lookAhead; rayVectorL *= lookAhead * .8f; rayVectorR *= lookAhead * .8f; // Encuentra las posibles colisiones Collision collision, collisionL, collisionR; collision = cd.getCollision(agente.getPosition(), rayVector); collisionL = cd.getCollision(agente.getPosition(), rayVectorL); collisionR = cd.getCollision(agente.getPosition(), rayVectorR); target = new AgenteNPC(targetPosition); if (collision == null && collisionL == null && collisionR == null) { return(base.getSteering(agente)); } if (collision != null) { targetPosition = collision.getPosition() + collision.getNormal() * avoidDistance; } if (collisionL != null) { targetPosition = collisionL.getPosition() + collisionL.getNormal() * avoidDistance; } if (collisionR != null) { targetPosition = collisionR.getPosition() + collisionR.getNormal() * avoidDistance; } target = new AgenteNPC(targetPosition); return(base.getSteering(agente)); }
public Steering getSteering(AgenteNPC agente) { Steering steering = new Steering(0, new Vector3(0, 0, 0)); AgenteNPC newTarget = new AgenteNPC(new Vector3(0, 0, 0)); Vector3 direction = target.position - agente.position; if (direction.magnitude == 0) { return(steering); } agente.orientation = Mathf.Atan2(direction.x, direction.z); return(base.getSteering(agente)); }
public override Steering getSteering(AgenteNPC agente) { Vector3 linear = target.getVelocity() - agente.getVelocity(); float maxAcc = agente.getMaxAcceleration(); linear /= timeToTarget; if (linear.magnitude > maxAcc) { linear = linear.normalized; linear *= maxAcc; } return(new Steering(0, linear)); }
public Steering getSteering(AgenteNPC agente) { float targetSpeed = 1; Vector3 targetVelocity; Vector3 lineal = Vector3.zero; float timeToTarget = 0.1f; float maxAcc = agente.maxAcceleration; Vector3 direction = target.getPosition() - agente.transform.position; float distance = direction.magnitude; if (distance < target.interiorRadius) { return(new Steering(0, Vector3.zero)); } if (distance > target.exteriorRadius) { targetSpeed = maxAcc; } else { targetSpeed = maxAcc * distance / target.exteriorRadius; } targetVelocity = direction; targetVelocity = targetVelocity.normalized; targetVelocity *= targetSpeed; lineal = targetVelocity - agente.velocity; lineal /= timeToTarget; if (lineal.magnitude > maxAcc) { lineal = lineal.normalized; lineal *= agente.maxAcceleration; } return(new Steering(0, lineal)); }
public Steering getSteering(AgenteNPC agente) { Vector3 direction = objetivoPursue.getPosition() - agente.getPosition(); float distance = direction.magnitude; float speed = agente.getVelocity().magnitude; if (speed <= distance / maxPrediction) { prediction = maxPrediction; } else { prediction = distance / speed; } target = new AgenteNPC(objetivoPursue.getPosition()); target.position += objetivoPursue.getVelocity() * prediction; return(base.getSteering(agente)); }
public override Steering getSteering(AgenteNPC agente) { float maxAcc = agente.getMaxAcceleration(); Steering steering = new Steering(0, Vector3.zero); Vector3 direction; float distance; float strength; foreach (Agente t in targets) { direction = agente.getPosition() - t.getPosition(); distance = direction.magnitude; if (distance < threshold) { strength = Mathf.Min(decayCoefficient / (distance * distance), maxAcc); direction = direction.normalized; steering.linear += strength * direction; } } return(steering); }
public void setTarget(AgenteNPC agente) { this.target = agente; }
public abstract Steering getSteering(AgenteNPC agente);
public override Steering getSteering(AgenteNPC agente) { Vector3 relativePos, relativeVelocity; float relativeSpeed, timeToCollision; float distance, minSeparation; float shortestTime = Mathf.Infinity; Agente firstTarget = null; Vector3 firstRelativePos = Vector3.zero, firstRelativeVelocity = Vector3.zero; float firstMinSeparation = 0, firstDistance = 0; foreach (Agente t in targets) { // Calculo del tiempo hasta la colision relativePos = t.getPosition() - agente.getPosition(); relativeVelocity = t.getVelocity() - agente.getVelocity(); relativeSpeed = relativeVelocity.magnitude; timeToCollision = Vector3.Dot(relativePos, relativeVelocity) / relativeSpeed * relativeSpeed; // Determina si va a haber una colision distance = relativePos.magnitude; minSeparation = distance - (relativeSpeed * timeToCollision); if (minSeparation > (2 * radius)) { continue; } // Comrpuebo si es el mas cercano/corto if (timeToCollision > 0 && timeToCollision < shortestTime) { shortestTime = timeToCollision; firstTarget = t; firstMinSeparation = minSeparation; firstDistance = distance; firstRelativePos = relativePos; firstRelativeVelocity = relativeVelocity; } } // Si no tenemos objtivo, salimos if (firstTarget == null) { return(new Steering(0, Vector3.zero)); } // Si vamos a colisionar y ya estamos colisionando, hacemos steering // basado en la posicion actual; if (firstMinSeparation <= 0 || firstDistance < 2 * radius) { relativePos = firstTarget.getPosition() - agente.getPosition(); } else { relativePos = firstRelativePos + (firstRelativeVelocity * shortestTime); } // Evitar al objetivo relativePos = relativePos.normalized; evasion = relativePos * agente.getMaxAcceleration(); return(new Steering(0, evasion)); }