private void InitializeMainCharacter(GameObject[] obstacles) { this.Priority = new PriorityMovement { Character = this.RedCharacter.KinematicData }; this.Blended = new BlendedMovement { Character = this.RedCharacter.KinematicData }; foreach (var obstacle in obstacles) { var avoidObstacleMovement = new DynamicAvoidObstacleWhiskers(obstacle) { MaxAcceleration = MAX_ACCELERATION, AvoidMargin = AVOID_MARGIN, MaxLookAhead = MAX_LOOK_AHEAD, Character = this.RedCharacter.KinematicData, MovementDebugColor = Color.magenta }; this.Blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 5.0f)); this.Priority.Movements.Add(avoidObstacleMovement); } foreach (var otherCharacter in this.Characters) { if (otherCharacter != this.RedCharacter) { var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData) { Character = this.RedCharacter.KinematicData, MaxAcceleration = MAX_ACCELERATION, CollisionRadius = COLLISION_RADIUS, MaxTimeLookAhead = MAX_TIME_LOOK_AHEAD, MovementDebugColor = Color.cyan }; this.Priority.Movements.Add(avoidCharacter); } } var wander = new DynamicWander { WanderOrientation = this.RedCharacter.KinematicData.orientation, Character = this.RedCharacter.KinematicData, WanderOffset = 20.0F, WanderRadius = 10.0F, WanderRate = WANDER_RATE, MaxAcceleration = MAX_ACCELERATION, MovementDebugColor = Color.yellow }; this.Priority.Movements.Add(wander); this.Blended.Movements.Add(new MovementWithWeight(wander, obstacles.Length + this.Characters.Count)); this.RedCharacter.Movement = this.Blended; }
public void InitializeMovement(GameObject[] obstacles, List <DynamicCharacter> characters) { foreach (var obstacle in obstacles) { //TODO: add your AvoidObstacle movement here var avoid = new DynamicAvoidShort { Character = this.character.KinematicData, avoidDistance = 5.0f, lookAhead = 15.0f, collisionDetector = obstacle.GetComponent <Collider>(), MaxAcceleration = MAX_ACCELERATION, whiskerLength = 7.5f }; this.blendedMovement.Movements.Add(new MovementWithWeight(avoid, 10.0f)); this.priorityMovement.Movements.Add(avoid); } foreach (var otherCharacter in characters) { if (otherCharacter != this.character) { //TODO: add your AvoidCharacter movement here var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData) { Character = this.character.KinematicData, maxAcceleration = MAX_ACCELERATION, collisionRadius = 3f, maxTimeLookAhead = 8f }; this.blendedMovement.Movements.Add(new MovementWithWeight(avoidCharacter, 10.0f)); this.priorityMovement.Movements.Add(avoidCharacter); } } /* TODO: add your wander behaviour here! */ var wander = new DynamicWander { Character = this.character.KinematicData, WanderOffset = 5, WanderRate = MathConstants.MATH_1_PI, MaxAcceleration = MAX_ACCELERATION }; this.priorityMovement.Movements.Add(wander); this.blendedMovement.Movements.Add(new MovementWithWeight(wander, 1)); this.character.Movement = this.blendedMovement; }
void OnDrawGizmos() { if (this.character != null && this.character.Movement != null) { foreach (DynamicMovement movement in this.priorityMovement.Movements) { if (movement != null && movement is DynamicWander) { DynamicWander wander = (DynamicWander)movement; Gizmos.color = Color.blue; Gizmos.DrawWireSphere(wander.CircleCenter, wander.WanderRadius); } } } }
/* * public SteeringOutput ObstaclePursue() * { * DynamicPursue sb = new DynamicPursue(agent.k, target.k, maxAcceleration, maxPrediction); * agent.DrawLine(agent.transform.position, sb.predictPos); * return ObstacleAvoidance(sb); * } */ public SteeringOutput ObstacleWander() { //if (startTime > wanderRate) //{ // wanderOrientation += randomBinomial() * wanderRate; // startTime = 0f; //} startTime += Time.deltaTime; DynamicSeek ds = new DynamicSeek(agent.k, new Kinematic(), maxAcceleration); DynamicWander dw = new DynamicWander(wanderOffset, wanderRadius, wanderRate, maxAcceleration, 100f, ds); targetPos = dw.targetPos; //agent.DrawCircle(dw.targetPos, wanderRadius); return(ObstacleAvoidance(dw)); }
public SteeringOutput Wander() { if (startTime > wanderRate) { wanderOrientation += randomBinomial() * wanderRate; startTime = 0f; } startTime += Time.deltaTime; DynamicAlign a = new DynamicAlign(agent.k, new Kinematic(), maxAngularAcceleration, maxRotation, targetRadiusA, slowRadiusA); DynamicFace f = new DynamicFace(new Kinematic(), a); DynamicSeek ds = new DynamicSeek(agent.k, new Kinematic(), maxAcceleration); DynamicWander dw = new DynamicWander(wanderOffset, wanderRadius, wanderRate, maxAcceleration, wanderOrientation, ds); SteeringOutput so = dw.getSteering(); agent.DrawCircle(dw.targetPos, wanderRadius); //agent.DrawLine(agent.k.position, asVector(wanderOrientation)); return(so); }
void Awake() { dynamicWander = new DynamicWander(GetComponent <Rigidbody>(), magnitude); }