protected override void OnUpdate() { foreach (var b in GetEntities <components>()) { Boid_Data x = b.boid; if (x.action == Boid_Data.Behaviour.explore) { MotherShipSetUp(b.ship); } } }
public override Vector3 Calculate(Boid_Data x) { Vector3 desired = x.target - x.transform.position; desired.Normalize(); desired *= x.maxSpeed; return(desired - x.velocity); //return Vector3.zero; }
public override Vector3 Calculate(Boid_Data x) { boid = x.target; float dist = Vector3.Distance(x.transform.position, target); if (dist < 20) { target = Random.insideUnitSphere * (radus); x.target = target; } return(x.GetComponent <SeekBehaviour>().Calculate(x)); }
public override Vector3 Calculate(Boid_Data x) { float dist = Vector3.Distance(x.target, x.transform.position); Vector3 target = path.waypoints[current]; x.target = target; bool ariveFlag = false; if (dist < distance) { if (path.looped) { current = (current + 1) % path.waypoints.Count; target = path.waypoints[current]; x.target = target; } else { if (current != path.waypoints.Count - 1) { current++; target = path.waypoints[current]; x.target = target; if (current == path.waypoints.Count) { Debug.Log("Trigger"); ariveFlag = true; } } } // return x.GetComponent<SeekBehaviour>().Calculate(x); } int stopAt = path.waypoints.Count; if (!path.looped && current == path.waypoints.Count - 1) { //target = path.waypoints[path.waypoints.Count]; // x.target = target; return(x.GetComponent <ArriveBehaviour>().Calculate(x)); } else { return(x.GetComponent <SeekBehaviour>().Calculate(x)); } //return Vector3.zero; }
public override Vector3 Calculate(Boid_Data x) { Vector3 disp = jitter * Random.insideUnitSphere * Time.deltaTime; target += disp; target.Normalize(); target *= radius; Vector3 localTarget = (Vector3.forward * distance) + target; worldTarget = transform.TransformPoint(localTarget); Vector3 targetFound = worldTarget - transform.position; x.target = targetFound; return(x.GetComponent <SeekBehaviour>().Calculate(x)); }
void FormUp(Boid_Data x) { x.GetComponent <Drone_Data>().enabled = false; x.GetComponent <CustomWonder>().weight = 0f; x.GetComponent <ArriveBehaviour>().weight = 1f; x.GetComponent <SeekBehaviour>().weight = 0f; x.GetComponent <Boid_Data>().target = x.GetComponent <Boid_Data>().formationPosistion; Explore(x); float dist = Vector3.Distance(x.transform.position, x.target); if (dist < 2f) { x.action = Boid_Data.Behaviour.InFormation; BeginTheBattle(); } }
public override Vector3 Calculate(Boid_Data x) { Vector3 toTarget = x.target - x.transform.position; float distance = toTarget.magnitude; if (distance < 0.1f) { return(Vector3.zero); } float ramped = x.maxSpeed * (distance / slowingDistance); float clamped = Mathf.Min(ramped, x.maxSpeed); Vector3 desired = clamped * (toTarget / distance); return(desired - x.velocity); }
public override Vector3 Calculate(Boid_Data x) { if (target != null) { float dist = Vector3.Distance(target.transform.position, x.transform.position); float time = dist / x.maxSpeed; targetPos = target.transform.position + (target.velocity * time); return(x.GetComponent <SeekBehaviour>().Calculate(x)); } else { weight = 0; GetComponent <CustomWonder>().weight = 1; GetComponent <Boid_Data>().action = Boid_Data.Behaviour.explore; return(Vector3.zero); } }
Vector3 Calculate(Boid_Data x) { Vector3 force = Vector3.zero; foreach (SteeringBehaviour b in x.movement) { //if (b.isActiveAndEnabled){ force += b.Calculate(x) * b.weight; //Debug.Log(force); float f = force.magnitude; if (f >= x.maxForce) { force = Vector3.ClampMagnitude(x.force, x.maxForce); break; } //} } return(force); }
protected override void OnUpdate() { foreach (var b in GetEntities <components>()) { Boid_Data x = b.boid; //tryed making a state machine setup but slowed down performace to 6 fps unknowen reasion if (x.action == Boid_Data.Behaviour.formation) { x.GetComponent <Drone_Data>().enemyTag = ""; FormUp(x); } else if (x.action == Boid_Data.Behaviour.InFormation) { TenHuh(x); } else { Explore(x); } } }
void Explore(Boid_Data x) { x.force = Calculate(x); x.acceleration = x.force / x.mass; x.velocity += x.acceleration * Time.deltaTime; x.transform.position += x.velocity * Time.deltaTime; if (x.velocity.magnitude > float.Epsilon) { Vector3 tempUp = Vector3.Lerp(x.transform.up, Vector3.up + (x.acceleration * x.banking), Time.deltaTime * 3.0f); x.transform.LookAt(x.transform.position + x.velocity, tempUp); x.transform.position += x.velocity * Time.deltaTime; x.velocity *= (1.0f - (x.damping * Time.deltaTime)); } x.currentTime += Time.deltaTime; if (x.currentTime > x.rayCastTimer) { x.currentTime = 0f; } }
private void Start() { target = GetComponent <Boid_Data>(); }
//[HideInInspector]; public abstract Vector3 Calculate(Boid_Data x);
void TenHuh(Boid_Data x) { x.velocity = Vector3.zero; x.transform.LookAt(x.LookAtPos); }