void FixedUpdate() { FishMovementUtils.RotateUpright(rb, transform); if (restTimer <= 0.0f) { currentForce = MoveTowardsTarget(); } else { currentForce = AdjustAltitude(restingHoverHeight); } }
public void UpdateFish() { Vector3 targetVector = (settings.target.position - transform.position) * settings.speed * settings.targetWeight; Vector3 collisionAvoidanceVector = Vector3.zero; Vector3 alignmentVector = Vector3.zero; Vector3 cohesionVector = Vector3.zero; Vector3 separationVector = Vector3.zero; // keep going in the current direction if no target if (settings.targetWeight == 0.0f || IsHeadingForCollision()) { Vector3 collisionAvoidDir = ObstacleRays(); collisionAvoidanceVector = collisionAvoidDir * settings.speed * settings.avoidCollisionWeight; } if (numPerceivedFlockmates != 0) { centreOfFlockmates /= numPerceivedFlockmates; Vector3 offsetToFlockmatesCentre = (centreOfFlockmates - transform.position); alignmentVector = avgFlockHeading * settings.speed * settings.alignWeight; cohesionVector = offsetToFlockmatesCentre * settings.speed * settings.cohesionWeight; separationVector = avgAvoidanceHeading * settings.speed * settings.separateWeight; } Vector3 sumVector = targetVector + collisionAvoidanceVector + alignmentVector + cohesionVector + separationVector; if (sumVector.magnitude > settings.maxSpeed) { sumVector = sumVector * (settings.maxSpeed / sumVector.magnitude); } FishMovementUtils.MoveTowardsTarget(rb, sumVector, settings.speed); FishMovementUtils.TurnToFace(rb, transform, rb.velocity); FishMovementUtils.RotateUpright(rb, transform); }
void FixedUpdate() { FishMovementUtils.RotateUpright(rb, transform); MoveTowardsTarget(); }