public bool DoStep() { vPref = goal - position; float distSqToGoal = vPref.sqrMagnitude; if (distSqToGoal <= goalRadius * goalRadius) { velocity = Vector2.zero; return(true); } // compute preferred velocity vPref *= prefSpeed / Mathf.Sqrt(distSqToGoal); // compute the new velocity of the agent ComputeForces(); F = Global.Clamp(F, maxAccel); velocity += F * Engine.timeStep; // Limit velocity to prefSpeed of agent if (velocity.sqrMagnitude > (prefSpeed * prefSpeed)) { velocity.Normalize(); velocity *= prefSpeed; } position += velocity * Engine.timeStep; // notify proximity database that our position has changed proximityToken.UpdateForNewPosition(ExtensionMethods.Vector2ToVector3(position)); MoveInRealWorld(); return(false); }
public void Init(int id, Vector2 position, Vector2 goal) { this.id = id; k = 1.5f; ksi = 0.91f; m = 2.4f; t0 = 4.47f; neighborDist = 11.6f; radius = 0.25f; prefSpeed = Random.Range(1.3f, 1.6f); this.position = position; this.goal = goal; // Add to the database proximityToken = Engine.Instance.GetSpatialDatabase.AllocateToken(this); // Notify proximity database that our position has changed proximityToken.UpdateForNewPosition(ExtensionMethods.Vector2ToVector3(position)); }
// Notify proximity database that our position has changed public void UpdateDB() { proximityToken.UpdateForNewPosition(ExtensionMethods.Vector2ToVector3(position)); }