public override Vector3 DoUpdate() { velocity = base.DoUpdate(); if (isDrawGizmo) { GizmosManager.DrawLine(toTargetLineRenderer, velocity, toTargetLineRendererColor, MaxSeeAhead); } else { GizmosManager.StopDraw(toTargetLineRenderer); } velocity += CollisionAvoidance(playerTransform.position, velocity, obstacles, MaxAvoidForce); velocity = TruncateFromSpeedAndForce(velocity); if (isDrawGizmo) { GizmosManager.DrawLine(velocityLineRenderer, velocity, velocityLineColor, playerManager.drawVelosityGizmoKoef); } else { GizmosManager.StopDraw(velocityLineRenderer); } return(velocity); }
public override void StopDrawGizmo() { GizmosManager.StopDraw(FollowLine); GizmosManager.StopDraw(velocityLineRenderer); GizmosManager.StopDraw(LeaderCircle); GizmosManager.StopDraw(LeaderAheadCircle); MinionsManager.inst.DeleteAllMinions(); }
public override Vector3 DoUpdate() { velocity = Vector3.Normalize(velocity) * maxVelocity; oldPosition = playerTransform.position; var currentDistance = CropByY(Leader.follovingPosition - playerTransform.position, 0); desiredVelocity = currentDistance.normalized * maxVelocity; var steering = desiredVelocity - velocity; if (steering.magnitude > maxForce) { steering = Vector3.Normalize(steering) * maxForce; } steering = new Vector3(steering.x / mass, 0, steering.z / mass); velocity = Vector3.Normalize(velocity + steering) * maxSpeed; if (currentDistance.magnitude < slowingRadius) { velocity *= (currentDistance.magnitude / slowingRadius); } if ((Vector3.Distance(Leader.Velocity.normalized * Leader.LeaderAhead + Leader.transform.position, this.transform.position) <= Leader.LeaderSightRadius) || (Vector3.Distance(Leader.transform.position, this.transform.position) <= Leader.LeaderSightRadius)) { var leaderAhead = LeaderAhead(); velocity += leaderAhead; SetColor(leaderAheadRenderColor); if (isDrawGizmo) { GizmosManager.DrawLine(leaderAvoidanceLineRenderer, leaderAhead, leaderAvoidanceLineRendererColor, Leader.LeaderAhead); } else { GizmosManager.StopDraw(leaderAvoidanceLineRenderer); } } else { velocity += Separation(); SetColor(normalRenderColor); GizmosManager.StopDraw(leaderAvoidanceLineRenderer); } velocity = TruncateFromSpeedAndForce(velocity); if (isDrawGizmo) { GizmosManager.DrawLine(velocityLineRenderer, velocity, velocityLineColor, playerManager.drawVelosityGizmoKoef); } else { GizmosManager.StopDraw(velocityLineRenderer); } return(velocity); }
public override void StopDrawGizmo() { GizmosManager.StopDraw(velocityLineRenderer); GizmosManager.StopDraw(collisionAvoidanceLineRenderer); GizmosManager.StopDraw(toTargetLineRenderer); GizmosManager.StopDraw(circleLineRenderer); if (obstacles.Count > 0) { foreach (var o in obstacles) { Destroy(o.gameObject); } } obstacles = new List <Obstacle>(); }
public override Vector3 DoUpdate() { velocity = base.DoUpdate() * -1; velocity *= ArrivalForce(); if (isDrawGizmo) { GizmosManager.DrawLine(velocityLineRenderer, velocity, velocityLineColor, playerManager.drawVelosityGizmoKoef); } else { GizmosManager.StopDraw(velocityLineRenderer); } return(velocity); }
public override Vector3 DoUpdate() { velocity = base.DoUpdate(); var circleCentre = Vector3.Normalize(velocity) * circleDistance; if (isDrawGizmo) { GizmosManager.DrawCircle(circleLineRenderer, circleCentre, circleRadius, circleColor); } else { GizmosManager.StopDraw(circleLineRenderer); } wanderAngle += Random.Range(-angleChangeRange, angleChangeRange); velocity += circleCentre + Vector3.Normalize(SetAngle(Vector3.one, wanderAngle)) * circleRadius; if (isDrawGizmo) { GizmosManager.DrawLine(angleLineRenderer, circleCentre, velocity, angleColor, 1); } else { GizmosManager.StopDraw(angleLineRenderer); } velocity = TruncateFromSpeedAndForce(velocity); if (isDrawGizmo) { GizmosManager.DrawLine(velocityLineRenderer, velocity, velocityLineColor, playerManager.drawVelosityGizmoKoef); } else { GizmosManager.StopDraw(velocityLineRenderer); } return(velocity); }
private Vector3 CollisionAvoidance(Vector3 playerPosition, Vector3 velocity, List <Obstacle> obstacles, float maxAvoidForce = 1) { velocity = Vector3.Normalize(velocity); var mostThreatening = FindMostThreateningObstacle(playerPosition, velocity * MaxSeeAhead, obstacles); if (mostThreatening != null) { var avoidance = Vector3.Normalize(CropByY(mostThreatening.transform.position - playerPosition, 0)) * -maxAvoidForce; if (isDrawGizmo) { GizmosManager.DrawCircle(circleLineRenderer, CropByY(mostThreatening.transform.position, -.5f) - playerPosition, mostThreatening.radius, circleLineRendererColor); GizmosManager.DrawLine(collisionAvoidanceLineRenderer, avoidance.normalized * maxAvoidForce, collisionAvoidanceLineRendererColor, maxAvoidForce); } return(avoidance); } GizmosManager.StopDraw(circleLineRenderer); GizmosManager.StopDraw(collisionAvoidanceLineRenderer); return(Vector3.zero); }
public override Vector3 DoUpdate() { velocity = base.DoUpdate(); follovingPosition = velocity.normalized * -DistanceToFollow; if (isDrawGizmo) { GizmosManager.DrawLine(FollowLine, follovingPosition, FollowLineColor, 1); GizmosManager.DrawCircle(LeaderCircle, Vector3.zero, LeaderSightRadius, LeaderCircleColor); GizmosManager.DrawCircle(LeaderAheadCircle, velocity * LeaderAhead, LeaderSightRadius, LeaderAheadCircleColor); } else { GizmosManager.StopDraw(FollowLine); GizmosManager.StopDraw(LeaderCircle); GizmosManager.StopDraw(LeaderAheadCircle); } follovingPosition += playerTransform.position; var currentDistance = Vector3.Distance(playerManager.targetTransform.position, playerTransform.position); if (currentDistance < slowingRadius) { velocity *= (currentDistance / slowingRadius); } if (isDrawGizmo) { GizmosManager.DrawLine(velocityLineRenderer, velocity, velocityLineColor, playerManager.drawVelosityGizmoKoef); } else { GizmosManager.StopDraw(velocityLineRenderer); } return(velocity); }
public override void StopDrawGizmo() { GizmosManager.StopDraw(velocityLineRenderer); GizmosManager.StopDraw(circleLineRenderer); GizmosManager.StopDraw(angleLineRenderer); }
public override void StopDrawGizmo() { GizmosManager.StopDraw(velocityLineRenderer); GizmosManager.StopDraw(leaderAvoidanceLineRenderer); }