/*public MovementOutput getAvoidMov(DynamicCharacter character, KinematicData OtherCharaterData) { var output = new MovementOutput(); UnityEngine.Vector3 deltaPos = OtherCharaterData.position - Character.position; UnityEngine.Vector3 deltaVel = OtherCharaterData.velocity - Character.velocity; float deltaSpeed = deltaVel.magnitude; if (deltaSpeed <= 0.001) return output; float timeToClosest = -UnityEngine.Vector3.Dot(deltaPos, deltaVel) / (deltaSpeed * deltaSpeed); if (timeToClosest > 20.0f) return output; float distance = deltaPos.magnitude; float minSeparation = distance - deltaSpeed * timeToClosest; if (minSeparation > 2 * 5.0f) return new MovementOutput(); if (minSeparation <= 0 || distance < 2 * 5.0f) output.linear = Character.position - OtherCharaterData.position; else output.linear = (deltaPos + deltaVel * timeToClosest) * -1; output.linear = output.linear.normalized * MaxAcceleration; return output; }*/ public MovementOutput deadLockMovement() { DynamicMovement output; output = new DynamicWander() { Character = this.character.KinematicData, MaxAcceleration = 20.0f, }; return output.GetMovement(); }
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) { //TODO: add your AvoidObstacle movement here DynamicAvoidObstacle avoidObstacleMovement = new DynamicAvoidObstacle(obstacle) { MaxAcceleration = MAX_ACCELERATION, AvoidMargin = AVOID_MARGIN, MaxLookAhead = MAX_LOOK_AHEAD, WhiskerLookAhead = WHISKER_LOOK_AHEAD, Character = this.RedCharacter.KinematicData, whiskersLookAhead = WHISKER_LOOK_AHEAD, MovementDebugColor = Color.magenta }; this.Blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, obstacles.Length + this.Characters.Count)); 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, MaximumTimeLookAhead = MAX_TIME_AHEAD, MovementDebugColor = Color.cyan }; this.Priority.Movements.Add(avoidCharacter); } } /* * TODO: add your wander behaviour here! */ var wander = new DynamicWander { Character = this.RedCharacter.KinematicData, MaxAcceleration = MAX_ACCELERATION, MovementDebugColor = Color.yellow }; this.Priority.Movements.Add(wander); this.Blended.Movements.Add(new MovementWithWeight(wander,5.0f)); this.RedCharacter.Movement = this.Blended; }
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) { //TODO: add your AvoidObstacle movement here //avoidObstacleMovement = new DynamicAvoidObstacle(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) { //TODO: add your AvoidCharacter movement here //var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData) //{ // Character = this.RedCharacter.KinematicData, // MaxAcceleration = MAX_ACCELERATION, // AvoidMargin = AVOID_MARGIN, // MovementDebugColor = Color.cyan //}; //this.Priority.Movements.Add(avoidCharacter); } } var redKinematicData = new KinematicData(new StaticData(this.RedCharacter.GameObject.transform.position)); var wander = new DynamicWander { Character = this.RedCharacter.KinematicData, Target = redKinematicData, 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; }
private void InitializeCharacter(DynamicCharacter character, GameObject[] obstacles) { var blended = new BlendedMovement { Character = character.KinematicData }; foreach (var obstacle in obstacles) { DynamicAvoidObstacle avoidObstacleMovement = new DynamicAvoidObstacle(obstacle, true) { MaxAcceleration = MAX_ACCELERATION, AvoidMargin = AVOID_MARGIN, MaxLookAhead = MAX_LOOK_AHEAD, Character = character.KinematicData, MovementDebugColor = Color.magenta }; blended.Movements.Add(new MovementWithWeight(avoidObstacleMovement, 15.0f)); } DynamicCohesion cohesion = new DynamicCohesion(Characters) { MaxAcceleration = MAX_ACCELERATION, MaxSpeed = MAX_SPEED, MovementDebugColor = Color.cyan, Character = character.KinematicData, Radius = 15f, FanAngle = MathConstants.MATH_PI_4 }; blended.Movements.Add(new MovementWithWeight(cohesion, 8.0f)); DynamicSeparation separation = new DynamicSeparation(Characters) { MaxAcceleration = MAX_ACCELERATION, MovementDebugColor = Color.green, Character = character.KinematicData, Radius = 10f, SeparationFactor = MAX_ACCELERATION * 1.3f }; blended.Movements.Add(new MovementWithWeight(separation, 10.0f)); DynamicFlockVelocityMatch velocityMatching = new DynamicFlockVelocityMatch(Characters) { MaxAcceleration = MAX_ACCELERATION, MovementDebugColor = Color.black, Character = character.KinematicData, Radius = 20f, FanAngle = MathConstants.MATH_PI_4 }; blended.Movements.Add(new MovementWithWeight(velocityMatching, 8.0f)); DynamicGoToPosition goToPosition = new DynamicGoToPosition() { MaxAcceleration = MAX_ACCELERATION, MaxSpeed = MAX_SPEED, Character = character.KinematicData, MovementDebugColor = Color.blue, Radius = 10.0f }; blended.Movements.Add(new MovementWithWeight(goToPosition, 8.0f)); GoToPositionMovements.Add(goToPosition); if (soloMove) { if (useWander) { var wander = new DynamicWander { MaxAcceleration = MAX_ACCELERATION, MovementDebugColor = Color.yellow, Character = character.KinematicData, TurnAngle = MathConstants.MATH_PI_4 / 2, WanderRadius = 2f, WanderOffset = 3f }; blended.Movements.Add(new MovementWithWeight(wander, 4.0f)); } else { var straightAhead = new DynamicStraightAhead { MaxAcceleration = MAX_ACCELERATION, MovementDebugColor = Color.yellow, Character = character.KinematicData }; blended.Movements.Add(new MovementWithWeight(straightAhead, 4.0f)); } } character.Movement = blended; }
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) { //TODO: add your AvoidObstacle movement here //avoidObstacleMovement = new DynamicAvoidObstacle(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) { //TODO: add your AvoidCharacter movement here //var avoidCharacter = new DynamicAvoidCharacter(otherCharacter.KinematicData) //{ // Character = this.RedCharacter.KinematicData, // MaxAcceleration = MAX_ACCELERATION, // AvoidMargin = AVOID_MARGIN, // MovementDebugColor = Color.cyan //}; //this.Priority.Movements.Add(avoidCharacter); } } /* * TODO: add your wander behaviour here! * var wander = new DynamicWander { .... Character = this.RedCharacter.KinematicData, MovementDebugColor = Color.yellow };*/ var wander = new DynamicWander { Character = this.RedCharacter.KinematicData, MovementDebugColor = Color.yellow, MaxAcceleration = MAX_ACCELERATION, WanderRate = 0.3f, WanderOffset = 10.0f, WanderRadius = 5.0f, DebugTarget = GameObject.Find("DebugTargetCube") }; var avoid = new DynamicAvoid { Character = this.RedCharacter.KinematicData, MovementDebugColor = Color.blue, MaxAcceleration = MAX_ACCELERATION, AvoidDistance = 6.0f, LookAhead = 20.0f, WhiskerAngle = 30.0f, WhiskerSize = 6.0f, DebugTargetCube = GameObject.Find("DebugTargetCube") }; this.Priority.Movements.Add(avoid); this.Priority.Movements.Add(wander); this.Blended.Movements.Add(new MovementWithWeight(wander,obstacles.Length+this.Characters.Count)); this.RedCharacter.Movement = this.Blended; }
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) { DynamicAvoidObstacle avoidObstacleMovement = new DynamicAvoidObstacle (obstacle, true) { MaxAcceleration = MAX_ACCELERATION, AvoidMargin = AVOID_MARGIN, MaxLookAhead = MAX_LOOK_AHEAD, Character = this.RedCharacter.KinematicData, MaxWhiskersLookAhead = 5f, WhiskersAngle = MathConstants.MATH_PI_4 * 0.75f, 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, AvoidMargin = AVOID_MARGIN, MaxTimeLookAhead = MAX_TIME_LOOK_AHEAD, MovementDebugColor = Color.cyan }; this.Priority.Movements.Add (avoidCharacter); } } var wander = new DynamicWander { MaxAcceleration = MAX_ACCELERATION, Character = this.RedCharacter.KinematicData, 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; }