protected override void SteeringUpdate(Steering steering)
    {
        float t = Time.fixedDeltaTime;

        Vector3 accel = steering.Force / mass;

        accel += Vector3.up * gravity;
        xform.Translate(velocity * t + 0.5f * accel * t * t, Space.World);

        velocity += accel * t;
        velocity -= velocity * linearDamp;
        float speed = velocity.magnitude;
        if(speed > maxSpeed) {
            velocity *= maxSpeed / speed;
        }

        Vector3 angAccel = steering.Torque / mass;

        xform.Rotate(angularVelocity * t + angAccel * t * t, Space.World);

        angularVelocity += angAccel * t;
        angularVelocity -= angularVelocity * angularDamp;
        float angSpeed = angularVelocity.magnitude;
        if(angSpeed > maxAngularSpeed) {
            angularVelocity *= maxAngularSpeed / angSpeed;
        }
    }
Exemple #2
0
 public void Start()
 {
     //get component reference
     myCharacterController = gameObject.GetComponent<CharacterController> ();
     steerer = gameObject.GetComponent<Steering> ();
     moveDirection = transform.forward;
 }
 private void Awake()
 {
     _engine = GetComponent<Engine>();
     _steering = GetComponent<Steering>();
     LevelManager.RaceStarted += EnableControls;
     LevelManager.RaceFinished += OnRaceFinished;
 }
Exemple #4
0
    public static Steering getSteering(float maxAcceleration, float maxSpeed, float targetRadius, float slowRadius,
        float predictionTime, Kinematic character, Kinematic target)
    {
        Steering steering = new Steering();

        Vector3 direction = target.position - character.position;
        float distance = direction.magnitude;

        if (distance < targetRadius)
        {
            steering.linear = Vector3.zero;
            steering.angular = 0.0f;
            return steering;
        }            

        float targetSpeed;
        if (distance > slowRadius)
            targetSpeed = maxSpeed;
        else
            targetSpeed = maxSpeed * distance / slowRadius;

        Vector3 targetVelocity = direction.normalized * targetSpeed;

        steering.linear = (targetVelocity - character.velocity) / predictionTime;

        if (steering.linear.magnitude > maxAcceleration)
            steering.linear = steering.linear.normalized * maxAcceleration;

        steering.angular = 0.0f;

        return steering;
    }
 void Start()
 {
     controller = gameObject.GetComponent<CharacterController>();
     steering = gameObject.GetComponent<Steering>();
     moveDirection = transform.forward;
     startPos = transform.position;
 }
    protected override void SteeringUpdate(Steering steering)
    {
        float t = Time.fixedDeltaTime;

        Vector3 accel = steering.Force / mass;

        if(controller.isGrounded) {
            if(velocity.y < 0f) {
                velocity.y = 0.0f;
            }
        } else {
            accel += Vector3.up * gravity;
        }
        controller.Move(velocity * t);// + 0.5f * accel * t * t);

        velocity += accel * t;
        velocity -= velocity * linearDamp;
        float speed = velocity.magnitude;
        if(speed > maxSpeed) {
            velocity *= maxSpeed / speed;
        }

        Vector3 angAccel = steering.Torque / mass;

        xform.Rotate(angularVelocity * t + angAccel * t * t, Space.World);

        angularVelocity += angAccel * t;
        angularVelocity -= angularVelocity * angularDamp;
        float angSpeed = angularVelocity.magnitude;
        if(angSpeed > maxAngularSpeed) {
            angularVelocity *= maxAngularSpeed / angSpeed;
        }
    }
    // Use this for initialization
    void Start()
    {
        characterController = gameObject.GetComponent<CharacterController> ();
        steering = gameObject.GetComponent<Steering> ();

        targetNode = 0;
    }
Exemple #8
0
 public void Start()
 {
     //get component reference
     myCharacterController = gameObject.GetComponent<CharacterController> ();
     steerer = gameObject.GetComponent<Steering> ();
     moveDirection = transform.forward;
     obstacles = GameObject.FindGameObjectsWithTag("Obstacle");
 }
Exemple #9
0
    public void Start()
    {
        Wander();
        //get component references
        characterController = gameObject.GetComponent<CharacterController> ();
        steering = gameObject.GetComponent<Steering> ();

        initMaxSpd = steering.maxSpeed;
        initMaxFrc = steering.maxForce;
    }
Exemple #10
0
    public void SetMotor(Motor motor)
    {
        if (motor != null && steering != null && motor.IsKinematic != steering.IsKinematic)
        {
            Debug.LogError((steering.IsKinematic ? "Kinematic" : "Dynamic") +  " steering cannot be used with " + (motor.IsKinematic ? "Kinematic" : "Dynamic") + " motor. Steering removed.");
            steering = null;
        }

        this.motor = motor;
    }
Exemple #11
0
    public static Steering getSteering(float maxAcceleration, float maxSpeed, Kinematic character, Kinematic target)
    {
        Steering steering = new Steering();

        steering.linear = character.position - target.position;

        steering.linear = steering.linear.normalized * maxAcceleration;
        steering.angular = 0;

        return steering;
    }
Exemple #12
0
 public void SetSteering(Steering steering)
 {
     if (motor != null && steering != null && motor.IsKinematic != steering.IsKinematic)
     {
         Debug.LogWarning("Steering behaviour must be " + (motor.IsKinematic ? "Kinematic" : "Dynamic"));
     }
     else
     {
         this.steering = steering;
     }
 }
Exemple #13
0
    public virtual Steering getSteering()
    {
        Steering steering = new Steering();

        steering.linear = character.position - target.position;

        steering.linear = steering.linear.normalized * maxAcceleration;
        steering.angular = 0;

        return steering;
    }
Exemple #14
0
    public void Update(Steering steering, float maxSpeed, float time)
    {
        position += velocity * time;
        orientation += rotation * time;

        velocity += steering.linear * time;
        rotation += steering.angular * time;

        if (velocity.magnitude > maxSpeed)
            velocity = velocity.normalized * maxSpeed;
    }
    public void Start()
    {
        //get component reference
        myCharacterController = gameObject.GetComponent<CharacterController> ();
        steerer = gameObject.GetComponent<Steering> ();
        moveDirection = transform.forward;

        minMax[0] = 92.0f;
        minMax[1] = 300.0f;
        minMax[2] = 20.0f;
        minMax[3] = 380.0f;
    }
Exemple #16
0
    public virtual Steering getSteering()
    {
        Steering steering = new Steering();

        steering.linear = target.position - character.position;

        steering.linear = steering.linear.normalized * maxAcceleration;
        steering.angular = 0;

        Debug.Log("Chasing: " + target.position);

        return steering;
    }
    // Use this for initialization
    void Start()
    {
        myCharacterController = gameObject.GetComponent<CharacterController>();
        steerer = gameObject.GetComponent<Steering>();
        moveDirection = transform.forward;

        obstacles = GameObject.FindGameObjectsWithTag("Obstacle");

        minMax[0] = 92.0f;
        minMax[1] = 300.0f;
        minMax[2] = 20.0f;
        minMax[3] = 380.0f;
    }
Exemple #18
0
    public Steering getSteering()
    {
        Steering steering = new Steering();

        steering.linear = target.velocity - character.velocity;
        steering.linear /= predictionTime;

        if (steering.linear.magnitude > maxAcceleration)
            steering.linear = steering.linear.normalized * maxAcceleration;

        steering.angular = 0;

        return steering;
    }
Exemple #19
0
    public static Steering getSteering(float maxAcceleration, float maxSpeed, float targetRadius, float slowRadius,
        float predictionTime, Kinematic character, Kinematic target)
    {
        Steering steering = new Steering();

        steering.linear = target.velocity - character.velocity;
        steering.linear /= predictionTime;

        if (steering.linear.magnitude > maxAcceleration)
            steering.linear = steering.linear.normalized * maxAcceleration;

        steering.angular = 0;

        return steering;
    }
Exemple #20
0
    public virtual Steering getSteering()
    {
        Vector3 direction = targetTransform.position - character.position;

        if (direction.magnitude == 0)
        {
            Steering steering = new Steering();
            steering.linear = Vector3.zero;
            steering.angular = 0.0f;
            return steering;
        }

        base.target = new Kinematic(targetTransform.position, - Mathf.Atan2(-direction.x, direction.z) * 180 / Mathf.PI);

        return base.getSteering();
    }
Exemple #21
0
    public static Steering getSteering(Kinematic character, Kinematic[] targets, float treshold, float maxAcceleration)
    {
        Steering steering = new Steering();

        for (int i = 0; i < targets.Length; i++)
        {
            Vector3 direction = targets[i].position - character.position;
            float distance = direction.magnitude;

            if (distance < treshold)
            {
                float strength = maxAcceleration * (treshold - distance) / treshold;
                steering.linear += strength * direction.normalized;
            }
        }

        return steering;
    }
Exemple #22
0
    public static Steering getSteering(float maxAngularAcceleration, float maxRotation, float targetRadius, float slowRadius,
        float predictionTime, Kinematic character, Kinematic target)
    {
        Vector3 direction = target.position - character.position;

        if (direction.magnitude == 0)
        {
            Steering steering = new Steering();
            steering.linear = Vector3.zero;
            steering.angular = 0.0f;
            return steering;
        }

        Kinematic newTarget = new Kinematic(target.position, - Mathf.Atan2(-direction.x, direction.z) * 180 / Mathf.PI);

        return Align_S.getSteering(maxAngularAcceleration, maxRotation, targetRadius, slowRadius,
            predictionTime, character, newTarget);
    }
    protected override void SteeringUpdate(Steering steering)
    {
        Vector3 desired = steering.Force;

        body.AddForce(desired);

        /* TODO speed clamp?
        velocity += accel * t;
        velocity -= velocity * linearDamp;
        float speed = velocity.magnitude;
        if(speed > maxSpeed) {
            velocity *= maxSpeed / speed;
        }
        */

        desired = steering.Torque * Mathf.Deg2Rad;

        if(body.isKinematic) {
            float t = Time.fixedDeltaTime;
            Vector3 angAccel = steering.Torque / body.mass;

            xform.Rotate(kinematicAngularVelocity * t + angAccel * t * t, Space.World);

            kinematicAngularVelocity += angAccel * t;
            kinematicAngularVelocity -= kinematicAngularVelocity * rigidbody.angularDrag;
            float angSpeed = kinematicAngularVelocity.magnitude;
            if(angSpeed > maxAngularSpeed) {
                kinematicAngularVelocity *= maxAngularSpeed / angSpeed;
            }
        } else {
            body.AddTorque(desired);
        }

        /* TODO angular speed clamp?
        angularVelocity += angAccel * t;
        angularVelocity -= angularVelocity * angularDamp;
        float angSpeed = angularVelocity.magnitude;
        if(angSpeed > maxAngularSpeed) {
            angularVelocity *= maxAngularSpeed / angSpeed;
        }
        */
    }
Exemple #24
0
    public static void UpdateSteering(Steering behavior, Bird bird, float dt)
    {
        if (behavior == null)
            return;

        var steering = behavior.GetSteering();

        if (!steering.IsNoSteering())
        {
            // update position
            bird.velocity += steering.linearVel * dt;

            bird.velocity = Vector3.ClampMagnitude(bird.velocity, bird.maxSpeed);

            if (bird.maxSpeed != 0f)
            {
                var rotation = Quaternion.LookRotation(bird.velocity);
                bird.transform.rotation = Quaternion.Slerp(bird.transform.rotation, rotation, 1f);
            }
        }
        else
            bird.GetComponent<Rigidbody>().velocity = Vector3.zero;
    }
Exemple #25
0
    public static Steering getSteering(float maxAngularAcceleration, float maxRotation, float targetRadius, float slowRadius,
        float predictionTime, Kinematic character, Kinematic target)
    {
        Steering steering = new Steering();

        float rotation = target.orientation - character.orientation;

        rotation = mapToRange(rotation);
        float rotationSize = Mathf.Abs(rotation);

        if (rotationSize < targetRadius)
        {
            steering.linear = Vector3.zero;
            steering.angular = 0.0f;
            return steering;
        }

        float targetRotation;
        if (rotationSize > slowRadius)
            targetRotation = maxRotation;
        else
            targetRotation = maxRotation * rotationSize / slowRadius;

        targetRotation *= rotation / rotationSize;

        steering.linear = Vector3.zero;
        steering.angular = (targetRotation - character.rotation) / predictionTime;

        float angularAcceleration = Mathf.Abs(steering.angular);
        if (angularAcceleration > maxAngularAcceleration)
        {
            steering.angular /= angularAcceleration;
            steering.angular *= maxAngularAcceleration;
        }

        return steering;
    }
Exemple #26
0
    public void Start()
    {
        //get component reference
        characterController = gameObject.GetComponent<CharacterController>();
        steering = gameObject.GetComponent<Steering>();
        moveDirection = transform.forward;
        steering.maxForce = 90;
        // tags behave as layers, but are called tags (and can't be used for masks)
        obstacles = GameObject.FindGameObjectsWithTag ("Obstacle");
        avoidDist = obstacles[0].GetComponent<Dimensions>().Radius + 10;

        //Find the player
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
        //Find the mom cat
        momCat = GameObject.FindGameObjectWithTag("Mom Cat");

        //Assign the target to be the first way point
        target = firstWayPointNode;

        //Set up everything else
        startPos = transform.position;
        capturedByPlayer = false;
        BehindPointRadius = BehindPoint.GetComponent<SphereCollider>().radius + BEHIND_POINT_RADIUS_OFFSET;
        isSearchingForWayPoint = false;
        returnedToMomCat = false;

        //Make the lost kitten not visible at first
        Visibility(false);
    }
Exemple #27
0
        public override IEnumerable <object> UpdateState()
        {
            Character Controlled = Character.Controlled;

            if (Controlled == null)
            {
                yield return(CoroutineStatus.Success);
            }

            foreach (Item item in Item.ItemList)
            {
                var wire = item.GetComponent <Wire>();
                if (wire != null && wire.Connections.Any(c => c != null))
                {
                    wire.Locked = true;
                }
            }

            //remove all characters except the controlled one to prevent any unintended monster attacks
            var existingCharacters = Character.CharacterList.FindAll(c => c != Controlled);

            foreach (Character c in existingCharacters)
            {
                c.Remove();
            }

            yield return(new WaitForSeconds(4.0f));

            infoBox = CreateInfoFrame("Use WASD to move and the mouse to look around");

            yield return(new WaitForSeconds(5.0f));

            //-----------------------------------

            infoBox = CreateInfoFrame("Open the door at your right side by highlighting the button next to it with your cursor and pressing E");

            Door tutorialDoor = Item.ItemList.Find(i => i.HasTag("tutorialdoor")).GetComponent <Door>();

            while (!tutorialDoor.IsOpen && Controlled.WorldPosition.X < tutorialDoor.Item.WorldPosition.X)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            yield return(new WaitForSeconds(2.0f));

            //-----------------------------------

            infoBox = CreateInfoFrame("Hold W or S to walk up or down stairs. Use shift to run.", true);

            while (infoBox != null)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            //-----------------------------------

            infoBox = CreateInfoFrame("At the moment the submarine has no power, which means that crucial systems such as the oxygen generator or the engine aren't running. Let's fix this: go to the upper left corner of the submarine, where you'll find a nuclear reactor.");

            Reactor reactor = Item.ItemList.Find(i => i.HasTag("tutorialreactor")).GetComponent <Reactor>();

            //reactor.MeltDownTemp = 20000.0f;

            while (Vector2.Distance(Controlled.Position, reactor.Item.Position) > 200.0f)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("The reactor requires fuel rods to generate power. You can grab one from the steel cabinet by walking next to it and pressing E.");

            while (Controlled.SelectedConstruction == null || Controlled.SelectedConstruction.Prefab.Identifier != "steelcabinet")
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("Pick up one of the fuel rods either by double-clicking or dragging and dropping it into your inventory.");

            while (!HasItem("fuelrod"))
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("Select the reactor by walking next to it and pressing E.");

            while (Controlled.SelectedConstruction != reactor.Item)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }
            yield return(new WaitForSeconds(0.5f));

            infoBox = CreateInfoFrame("Load the fuel rod into the reactor by dropping it into any of the 5 slots.");

            while (reactor.AvailableFuel <= 0.0f)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("The reactor is now fueled up. Try turning it on by increasing the fission rate.");

            while (reactor.FissionRate <= 0.0f)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }
            yield return(new WaitForSeconds(0.5f));

            infoBox = CreateInfoFrame("The reactor core has started generating heat, which in turn generates power for the submarine. The power generation is very low at the moment,"
                                      + " because the reactor is set to shut itself down when the temperature rises above 500 degrees Celsius. You can adjust the temperature limit by changing the \"Shutdown Temperature\" in the control panel.", true);

            //TODO: reimplement

            /*while (infoBox != null)
             * {
             *  reactor.ShutDownTemp = Math.Min(reactor.ShutDownTemp, 5000.0f);
             *  yield return Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running;
             * }
             * yield return new WaitForSeconds(0.5f);
             *
             * infoBox = CreateInfoFrame("The amount of power generated by the reactor should be kept close to the amount of power consumed by the devices in the submarine. "
             + "If there isn't enough power, devices won't function properly (or at all), and if there's too much power, some devices may be damaged."
             + " Try to raise the temperature of the reactor close to 3000 degrees by adjusting the fission and cooling rates.", true);
             +
             + while (Math.Abs(reactor.Temperature - 3000.0f) > 100.0f)
             + {
             +  reactor.AutoTemp = false;
             +  reactor.ShutDownTemp = Math.Min(reactor.ShutDownTemp, 5000.0f);
             +  yield return Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running;
             + }
             + yield return new WaitForSeconds(0.5f);
             +
             + infoBox = CreateInfoFrame("Looks like we're up and running! Now you should turn on the \"Automatic temperature control\", which will make the reactor "
             + "automatically adjust the temperature to a suitable level. Even though it's an easy way to keep the reactor up and running most of the time, "
             + "you should keep in mind that it changes the temperature very slowly and carefully, which may cause issues if there are sudden changes in grid load.");
             +
             + while (!reactor.AutoTemp)
             + {
             +  yield return Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running;
             + }*/
            yield return(new WaitForSeconds(0.5f));

            infoBox = CreateInfoFrame("That's the basics of operating the reactor! Now that there's power available for the engines, it's time to get the submarine moving. "
                                      + "Deselect the reactor by pressing E and head to the command room at the right edge of the vessel.");

            Steering steering = Item.ItemList.Find(i => i.HasTag("tutorialsteering")).GetComponent <Steering>();
            Sonar    sonar    = steering.Item.GetComponent <Sonar>();

            while (Vector2.Distance(Controlled.Position, steering.Item.Position) > 150.0f)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            CoroutineManager.StartCoroutine(KeepReactorRunning(reactor));

            infoBox = CreateInfoFrame("Select the navigation terminal by walking next to it and pressing E.");

            while (Controlled.SelectedConstruction != steering.Item)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }
            yield return(new WaitForSeconds(0.5f));

            infoBox = CreateInfoFrame("There seems to be something wrong with the navigation terminal." +
                                      " There's nothing on the monitor, so it's probably out of power. The reactor must still be"
                                      + " running or the lights would've gone out, so it's most likely a problem with the wiring."
                                      + " Deselect the terminal by pressing E to start checking the wiring.");

            while (Controlled.SelectedConstruction == steering.Item)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }
            yield return(new WaitForSeconds(1.0f));

            infoBox = CreateInfoFrame("You need a screwdriver to check the wiring of the terminal."
                                      + " Equip a screwdriver by pulling it to either of the slots with a hand symbol, and then use it on the terminal by left clicking.");

            while (Controlled.SelectedConstruction != steering.Item ||
                   Controlled.SelectedItems.FirstOrDefault(i => i != null && i.Prefab.Identifier == "screwdriver") == null)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }


            infoBox = CreateInfoFrame("Here you can see all the wires connected to the terminal. Apparently there's no wire"
                                      + " going into the to the power connection - that's why the monitor isn't working."
                                      + " You should find a piece of wire to connect it. Try searching some of the cabinets scattered around the sub.");

            while (!HasItem("wire"))
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("Head back to the navigation terminal to fix the wiring.");

            PowerTransfer junctionBox = Item.ItemList.Find(i => i != null && i.HasTag("tutorialjunctionbox")).GetComponent <PowerTransfer>();

            while ((Controlled.SelectedConstruction != junctionBox.Item &&
                    Controlled.SelectedConstruction != steering.Item) ||
                   Controlled.SelectedItems.FirstOrDefault(i => i != null && i.Prefab.Identifier == "screwdriver") == null)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            if (Controlled.SelectedItems.FirstOrDefault(i => i != null && i.GetComponent <Wire>() != null) == null)
            {
                infoBox = CreateInfoFrame("Equip the wire by dragging it to one of the slots with a hand symbol.");

                while (Controlled.SelectedItems.FirstOrDefault(i => i != null && i.GetComponent <Wire>() != null) == null)
                {
                    yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
                }
            }

            infoBox = CreateInfoFrame("You can see the equipped wire at the middle of the connection panel. Drag it to the power connector.");

            var steeringConnection = steering.Item.Connections.Find(c => c.Name.Contains("power"));

            while (steeringConnection.Wires.FirstOrDefault(w => w != null) == null)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("Now you have to connect the other end of the wire to a power source. "
                                      + "The junction box in the room just below the command room should do.");

            while (Controlled.SelectedConstruction != null)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            yield return(new WaitForSeconds(2.0f));

            infoBox = CreateInfoFrame("You can now move the other end of the wire around, and attach it on the wall by left clicking or "
                                      + "remove the previous attachment by right clicking. Or if you don't care for neatly laid out wiring, you can just "
                                      + "run it straight to the junction box.");

            while (Controlled.SelectedConstruction == null || Controlled.SelectedConstruction.GetComponent <PowerTransfer>() == null)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("Connect the wire to the junction box by pulling it to the power connection, the same way you did with the navigation terminal.");

            while (sonar.Voltage < 0.1f)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("Great! Now we should be able to get moving.");


            while (Controlled.SelectedConstruction != steering.Item)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("You can take a look at the area around the sub by selecting the \"Active Sonar\" checkbox.");

            while (!sonar.IsActive)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }
            yield return(new WaitForSeconds(0.5f));

            infoBox = CreateInfoFrame("The blue rectangle in the middle is the submarine, and the flickering shapes outside it are the walls of an underwater cavern. "
                                      + "Try moving the submarine by clicking somewhere on the monitor and dragging the pointer to the direction you want to go to.");

            while (steering.TargetVelocity == Vector2.Zero && steering.TargetVelocity.Length() < 50.0f)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }
            yield return(new WaitForSeconds(4.0f));

            infoBox = CreateInfoFrame("The submarine moves up and down by pumping water in and out of the two ballast tanks at the bottom of the submarine. "
                                      + "The engine at the back of the sub moves it forwards and backwards.", true);

            while (infoBox != null)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("Steer the submarine downwards, heading further into the cavern.");

            while (Submarine.MainSub.WorldPosition.Y > 32000.0f)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }
            yield return(new WaitForSeconds(1.0f));

            var moloch = Character.Create(
                "Content/Characters/Moloch/moloch.xml",
                steering.Item.WorldPosition + new Vector2(3000.0f, -500.0f), "");

            moloch.PlaySound(CharacterSound.SoundType.Attack);

            yield return(new WaitForSeconds(1.0f));

            infoBox = CreateInfoFrame("Uh-oh... Something enormous just appeared on the sonar.");

            List <Structure> windows = new List <Structure>();

            foreach (Structure s in Structure.WallList)
            {
                if (s.CastShadow || !s.HasBody)
                {
                    continue;
                }

                if (s.Rect.Right > steering.Item.CurrentHull.Rect.Right)
                {
                    windows.Add(s);
                }
            }

            float slowdownTimer = 1.0f;
            bool  broken        = false;

            do
            {
                steering.TargetVelocity = Vector2.Zero;

                slowdownTimer = Math.Max(0.0f, slowdownTimer - CoroutineManager.DeltaTime * 0.3f);
                Submarine.MainSub.Velocity *= slowdownTimer;

                moloch.AIController.SelectTarget(steering.Item.CurrentHull.AiTarget);
                Vector2 steeringDir = windows[0].WorldPosition - moloch.WorldPosition;
                if (steeringDir != Vector2.Zero)
                {
                    steeringDir = Vector2.Normalize(steeringDir);
                }

                moloch.AIController.SteeringManager.SteeringManual(CoroutineManager.DeltaTime, steeringDir * 100.0f);

                foreach (Structure window in windows)
                {
                    for (int i = 0; i < window.SectionCount; i++)
                    {
                        if (!window.SectionIsLeaking(i))
                        {
                            continue;
                        }
                        broken = true;
                        break;
                    }
                    if (broken)
                    {
                        break;
                    }
                }
                if (broken)
                {
                    break;
                }

                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            } while (!broken);

            //fix everything except the command windows
            foreach (Structure w in Structure.WallList)
            {
                bool isWindow = windows.Contains(w);

                for (int i = 0; i < w.SectionCount; i++)
                {
                    if (!w.SectionIsLeaking(i))
                    {
                        continue;
                    }

                    if (isWindow)
                    {
                        //decrease window damage to slow down the leaking
                        w.AddDamage(i, -w.SectionDamage(i) * 0.48f);
                    }
                    else
                    {
                        w.AddDamage(i, -100000.0f);
                    }
                }
            }

            Submarine.MainSub.GodMode = true;

            var capacitor1 = Item.ItemList.Find(i => i.HasTag("capacitor1")).GetComponent <PowerContainer>();
            var capacitor2 = Item.ItemList.Find(i => i.HasTag("capacitor1")).GetComponent <PowerContainer>();

            CoroutineManager.StartCoroutine(KeepEnemyAway(moloch, new PowerContainer[] { capacitor1, capacitor2 }));

            infoBox = CreateInfoFrame("The hull has been breached! Close all the doors to the command room to stop the water from flooding the entire sub!");

            Door commandDoor1 = Item.ItemList.Find(i => i.HasTag("commanddoor1")).GetComponent <Door>();
            Door commandDoor2 = Item.ItemList.Find(i => i.HasTag("commanddoor2")).GetComponent <Door>();

            //wait until the player is out of the room and the doors are closed
            while (Controlled.WorldPosition.X > commandDoor1.Item.WorldPosition.X ||
                   (commandDoor1.IsOpen || commandDoor2.IsOpen))
            {
                //prevent the hull from filling up completely and crushing the player
                steering.Item.CurrentHull.WaterVolume = Math.Min(steering.Item.CurrentHull.WaterVolume, steering.Item.CurrentHull.Volume * 0.9f);
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }


            infoBox = CreateInfoFrame("You should quickly find yourself a diving mask or a diving suit. " +
                                      "There are some in the room next to the airlock.");

            bool divingMaskSelected = false;

            while (!HasItem("divingmask") && !HasItem("divingsuit"))
            {
                if (!divingMaskSelected &&
                    Controlled.FocusedItem != null && Controlled.FocusedItem.Prefab.Identifier == "divingsuit")
                {
                    infoBox = CreateInfoFrame("There can only be one item in each inventory slot, so you need to take off "
                                              + "the jumpsuit if you wish to wear a diving suit.");

                    divingMaskSelected = true;
                }

                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            if (HasItem("divingmask"))
            {
                infoBox = CreateInfoFrame("The diving mask will let you breathe underwater, but it won't protect from the water pressure outside the sub. " +
                                          "It should be fine for the situation at hand, but you still need to find an oxygen tank and drag it into the same slot as the mask." +
                                          "You should grab one or two from one of the cabinets.");
            }
            else if (HasItem("divingsuit"))
            {
                infoBox = CreateInfoFrame("In addition to letting you breathe underwater, the suit will protect you from the water pressure outside the sub " +
                                          "(unlike the diving mask). However, you still need to drag an oxygen tank into the same slot as the suit to supply oxygen. " +
                                          "You should grab one or two from one of the cabinets.");
            }

            while (!HasItem("oxygentank"))
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            yield return(new WaitForSeconds(5.0f));

            infoBox = CreateInfoFrame("Now you should stop the creature attacking the submarine before it does any more damage. Head to the railgun room at the upper right corner of the sub.");

            var railGun = Item.ItemList.Find(i => i.GetComponent <Turret>() != null);

            while (Vector2.Distance(Controlled.Position, railGun.Position) > 500)
            {
                yield return(new WaitForSeconds(1.0f));
            }

            infoBox = CreateInfoFrame("The railgun requires a large power surge to fire. The reactor can't provide a surge large enough, so we need to use the "
                                      + " supercapacitors in the railgun room. The capacitors need to be charged first; select them and crank up the recharge rate.");

            while (capacitor1.RechargeSpeed < 0.5f && capacitor2.RechargeSpeed < 0.5f)
            {
                yield return(new WaitForSeconds(1.0f));
            }

            infoBox = CreateInfoFrame("The capacitors take some time to recharge, so now is a good " +
                                      "time to head to the room below and load some shells for the railgun.");


            var loader = Item.ItemList.Find(i => i.Prefab.Identifier == "railgunloader").GetComponent <ItemContainer>();

            while (Math.Abs(Controlled.Position.Y - loader.Item.Position.Y) > 80)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("Grab one of the shells. You can load it by selecting the railgun loader and dragging the shell to. "
                                      + "one of the free slots. You need two hands to carry a shell, so make sure you don't have anything else in either hand.");

            while (loader.Item.ContainedItems.FirstOrDefault(i => i != null && i.Prefab.Identifier == "railgunshell") == null)
            {
                //TODO: reimplement
                //moloch.Health = 50.0f;

                capacitor1.Charge += 5.0f;
                capacitor2.Charge += 5.0f;
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("Now we're ready to shoot! Select the railgun controller.");

            while (Controlled.SelectedConstruction == null || Controlled.SelectedConstruction.Prefab.Identifier != "railguncontroller")
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            moloch.AnimController.SetPosition(ConvertUnits.ToSimUnits(Controlled.WorldPosition + Vector2.UnitY * 600.0f));

            infoBox = CreateInfoFrame("Use the right mouse button to aim and wait for the creature to come closer. When you're ready to shoot, "
                                      + "press the left mouse button.");

            while (!moloch.IsDead)
            {
                if (moloch.WorldPosition.Y > Controlled.WorldPosition.Y + 600.0f)
                {
                    moloch.AIController.SteeringManager.SteeringManual(CoroutineManager.DeltaTime, Controlled.WorldPosition - moloch.WorldPosition);
                }

                moloch.AIController.SelectTarget(Controlled.AiTarget);
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            Submarine.MainSub.GodMode = false;

            infoBox = CreateInfoFrame("The creature has died. Now you should fix the damages in the control room: " +
                                      "Grab a welding tool from the closet in the railgun room.");

            while (!HasItem("weldingtool"))
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("The welding tool requires fuel to work. Grab a welding fuel tank and attach it to the tool " +
                                      "by dragging it into the same slot.");

            do
            {
                var weldingTool = Controlled.Inventory.Items.FirstOrDefault(i => i != null && i.Prefab.Identifier == "weldingtool");
                if (weldingTool != null &&
                    weldingTool.ContainedItems.FirstOrDefault(contained => contained != null && contained.Prefab.Identifier == "weldingfueltank") != null)
                {
                    break;
                }

                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            } while (true);


            infoBox = CreateInfoFrame("You can aim with the tool using the right mouse button and weld using the left button. " +
                                      "Head to the command room to fix the leaks there.");

            do
            {
                broken = false;
                foreach (Structure window in windows)
                {
                    for (int i = 0; i < window.SectionCount; i++)
                    {
                        if (!window.SectionIsLeaking(i))
                        {
                            continue;
                        }
                        broken = true;
                        break;
                    }
                    if (broken)
                    {
                        break;
                    }
                }

                yield return(new WaitForSeconds(1.0f));
            } while (broken);

            infoBox = CreateInfoFrame("The hull is fixed now, but there's still quite a bit of water inside the sub. It should be pumped out "
                                      + "using the bilge pump in the room at the bottom of the submarine.");

            Pump pump = Item.ItemList.Find(i => i.HasTag("tutorialpump")).GetComponent <Pump>();

            while (Vector2.Distance(Controlled.Position, pump.Item.Position) > 100.0f)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("The two pumps inside the ballast tanks "
                                      + "are connected straight to the navigation terminal and can't be manually controlled unless you mess with their wiring, " +
                                      "so you should only use the pump in the middle room to pump out the water. Select it, turn it on and adjust the pumping speed " +
                                      "to start pumping water out.", true);

            while (infoBox != null)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }


            bool brokenMsgShown = false;

            Item brokenBox = null;

            while (pump.FlowPercentage > 0.0f || pump.CurrFlow <= 0.0f || !pump.IsActive)
            {
                if (!brokenMsgShown && pump.Voltage < pump.MinVoltage && Controlled.SelectedConstruction == pump.Item)
                {
                    brokenMsgShown = true;

                    infoBox = CreateInfoFrame("Looks like the pump isn't getting any power. The water must have short-circuited some of the junction "
                                              + "boxes. You can check which boxes are broken by selecting them.");

                    while (true)
                    {
                        if (Controlled.SelectedConstruction != null &&
                            Controlled.SelectedConstruction.GetComponent <PowerTransfer>() != null &&
                            Controlled.SelectedConstruction.Condition == 0.0f)
                        {
                            brokenBox = Controlled.SelectedConstruction;

                            infoBox = CreateInfoFrame("Here's our problem: this junction box is broken. Luckily engineers are adept at fixing electrical devices - "
                                                      + "you just need to find a spare wire and click the \"Fix\"-button to repair the box.");
                            break;
                        }

                        if (pump.Voltage > pump.MinVoltage)
                        {
                            break;
                        }

                        yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
                    }
                }

                if (brokenBox != null && brokenBox.ConditionPercentage > 50.0f && pump.Voltage < pump.MinVoltage)
                {
                    yield return(new WaitForSeconds(1.0f));

                    if (pump.Voltage < pump.MinVoltage)
                    {
                        infoBox = CreateInfoFrame("The pump is still not running. Check if there are more broken junction boxes between the pump and the reactor.");
                    }
                    brokenBox = null;
                }

                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("The pump is up and running. Wait for the water to be drained out.");

            while (pump.Item.CurrentHull.WaterVolume > 1000.0f)
            {
                yield return(Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            infoBox = CreateInfoFrame("That was all there is to this tutorial! Now you should be able to handle " +
                                      "most of the basic tasks on board the submarine.");

            Completed = true;

            yield return(new WaitForSeconds(4.0f));

            Controlled = null;
            GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
            GameMain.LightManager.LosEnabled  = false;

            var cinematic = new RoundEndCinematic(Submarine.MainSub, GameMain.GameScreen.Cam, 5.0f);

            while (cinematic.Running)
            {
                yield return(Controlled != null && Controlled.IsDead ? CoroutineStatus.Success : CoroutineStatus.Running);
            }

            Submarine.Unload();
            GameMain.MainMenuScreen.Select();

            yield return(CoroutineStatus.Success);
        }
Exemple #28
0
 public void SetSteering(Steering steering)
 {
     this.steering = steering;
 }
Exemple #29
0
        public override void Start()
        {
            base.Start();

            captain          = Character.Controlled;
            radioSpeakerName = TextManager.Get("Tutorial.Radio.Watchman");
            GameMain.GameSession.CrewManager.AllowCharacterSwitch = false;

            var revolver = FindOrGiveItem(captain, "revolver");

            revolver.Unequip(captain);
            captain.Inventory.RemoveItem(revolver);

            var captainscap =
                captain.Inventory.FindItemByIdentifier("captainscap1") ??
                captain.Inventory.FindItemByIdentifier("captainscap2") ??
                captain.Inventory.FindItemByIdentifier("captainscap3");

            if (captainscap != null)
            {
                captainscap.Unequip(captain);
                captain.Inventory.RemoveItem(captainscap);
            }

            var captainsuniform =
                captain.Inventory.FindItemByIdentifier("captainsuniform1") ??
                captain.Inventory.FindItemByIdentifier("captainsuniform2") ??
                captain.Inventory.FindItemByIdentifier("captainsuniform3");

            if (captainsuniform != null)
            {
                captainsuniform.Unequip(captain);
                captain.Inventory.RemoveItem(captainsuniform);
            }

            var steerOrder = Order.GetPrefab("steer");

            captain_steerIcon      = steerOrder.SymbolSprite;
            captain_steerIconColor = steerOrder.Color;

            // Room 2
            captain_equipmentObjectiveSensor = Item.ItemList.Find(i => i.HasTag("captain_equipmentobjectivesensor")).GetComponent <MotionSensor>();
            captain_equipmentCabinet         = Item.ItemList.Find(i => i.HasTag("captain_equipmentcabinet")).GetComponent <ItemContainer>();
            captain_firstDoor      = Item.ItemList.Find(i => i.HasTag("captain_firstdoor")).GetComponent <Door>();
            captain_firstDoorLight = Item.ItemList.Find(i => i.HasTag("captain_firstdoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(captain_firstDoor, captain_firstDoorLight, true);

            // Room 3
            captain_medicObjectiveSensor = Item.ItemList.Find(i => i.HasTag("captain_medicobjectivesensor")).GetComponent <MotionSensor>();
            captain_medicSpawnPos        = Item.ItemList.Find(i => i.HasTag("captain_medicspawnpos")).WorldPosition;
            tutorial_submarineDoor       = Item.ItemList.Find(i => i.HasTag("tutorial_submarinedoor")).GetComponent <Door>();
            tutorial_submarineDoorLight  = Item.ItemList.Find(i => i.HasTag("tutorial_submarinedoorlight")).GetComponent <LightComponent>();
            var medicInfo = new CharacterInfo(CharacterPrefab.HumanSpeciesName, "", JobPrefab.Get("medicaldoctor"));

            captain_medic        = Character.Create(medicInfo, captain_medicSpawnPos, "medicaldoctor");
            captain_medic.TeamID = Character.TeamType.Team1;
            captain_medic.GiveJobItems(null);
            captain_medic.CanSpeak = captain_medic.AIController.Enabled = false;
            SetDoorAccess(tutorial_submarineDoor, tutorial_submarineDoorLight, false);

            // Submarine
            captain_enteredSubmarineSensor    = Item.ItemList.Find(i => i.HasTag("captain_enteredsubmarinesensor")).GetComponent <MotionSensor>();
            tutorial_submarineReactor         = Item.ItemList.Find(i => i.HasTag("engineer_submarinereactor")).GetComponent <Reactor>();
            captain_navConsole                = Item.ItemList.Find(i => i.HasTag("command")).GetComponent <Steering>();
            captain_navConsoleCustomInterface = Item.ItemList.Find(i => i.HasTag("command")).GetComponent <CustomInterface>();
            captain_sonar         = captain_navConsole.Item.GetComponent <Sonar>();
            captain_statusMonitor = Item.ItemList.Find(i => i.HasTag("captain_statusmonitor"));

            tutorial_submarineReactor.CanBeSelected = false;
            tutorial_submarineReactor.IsActive      = tutorial_submarineReactor.AutoTemp = false;

            tutorial_lockedDoor_1 = Item.ItemList.Find(i => i.HasTag("tutorial_lockeddoor_1")).GetComponent <Door>();
            tutorial_lockedDoor_2 = Item.ItemList.Find(i => i.HasTag("tutorial_lockeddoor_2")).GetComponent <Door>();
            SetDoorAccess(tutorial_lockedDoor_1, null, false);
            SetDoorAccess(tutorial_lockedDoor_2, null, false);

            var mechanicInfo = new CharacterInfo(CharacterPrefab.HumanSpeciesName, "", JobPrefab.Get("mechanic"));

            captain_mechanic        = Character.Create(mechanicInfo, WayPoint.GetRandom(SpawnType.Human, mechanicInfo.Job, Submarine.MainSub).WorldPosition, "mechanic");
            captain_mechanic.TeamID = Character.TeamType.Team1;
            captain_mechanic.GiveJobItems();

            var securityInfo = new CharacterInfo(CharacterPrefab.HumanSpeciesName, "", JobPrefab.Get("securityofficer"));

            captain_security        = Character.Create(securityInfo, WayPoint.GetRandom(SpawnType.Human, securityInfo.Job, Submarine.MainSub).WorldPosition, "securityofficer");
            captain_security.TeamID = Character.TeamType.Team1;
            captain_security.GiveJobItems();

            var engineerInfo = new CharacterInfo(CharacterPrefab.HumanSpeciesName, "", JobPrefab.Get("engineer"));

            captain_engineer        = Character.Create(engineerInfo, WayPoint.GetRandom(SpawnType.Human, engineerInfo.Job, Submarine.MainSub).WorldPosition, "engineer");
            captain_engineer.TeamID = Character.TeamType.Team1;
            captain_engineer.GiveJobItems();

            captain_mechanic.CanSpeak             = captain_security.CanSpeak = captain_engineer.CanSpeak = false;
            captain_mechanic.AIController.Enabled = captain_security.AIController.Enabled = captain_engineer.AIController.Enabled = false;
        }
Exemple #30
0
        public RespawnManager(NetworkMember networkMember, SubmarineInfo shuttleInfo)
            : base(null)
        {
            this.networkMember = networkMember;

            if (shuttleInfo != null)
            {
                RespawnShuttle = new Submarine(shuttleInfo, true);
                RespawnShuttle.PhysicsBody.FarseerBody.OnCollision += OnShuttleCollision;

                //prevent wifi components from communicating between the respawn shuttle and other subs
                List <WifiComponent> wifiComponents = new List <WifiComponent>();
                foreach (Item item in Item.ItemList)
                {
                    if (item.Submarine == RespawnShuttle)
                    {
                        wifiComponents.AddRange(item.GetComponents <WifiComponent>());
                    }
                }
                foreach (WifiComponent wifiComponent in wifiComponents)
                {
                    wifiComponent.TeamID = Character.TeamType.FriendlyNPC;
                }

                ResetShuttle();

                shuttleDoors = new List <Door>();
                foreach (Item item in Item.ItemList)
                {
                    if (item.Submarine != RespawnShuttle)
                    {
                        continue;
                    }

                    var steering = item.GetComponent <Steering>();
                    if (steering != null)
                    {
                        shuttleSteering = steering;
                    }

                    var door = item.GetComponent <Door>();
                    if (door != null)
                    {
                        shuttleDoors.Add(door);
                    }

                    //lock all wires to prevent the players from messing up the electronics
                    var connectionPanel = item.GetComponent <ConnectionPanel>();
                    if (connectionPanel != null)
                    {
                        foreach (Connection connection in connectionPanel.Connections)
                        {
                            foreach (Wire wire in connection.Wires)
                            {
                                if (wire != null)
                                {
                                    wire.Locked = true;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                RespawnShuttle = null;
            }

#if SERVER
            if (networkMember is GameServer server)
            {
                maxTransportTime = server.ServerSettings.MaxTransportTime;
            }
#endif
        }
Exemple #31
0
 public void RegisterSteering(Steering steering)
 {
     _allSteerings.Add(steering);
     steering.Agent = _agent;
 }
        /// <summary>
        /// Causes the agent to make one step away from  the objectPosition
        /// The speed of avoid is goverened by this agents speed
        /// </summary>
        public void FleeFrom(SOFT152Vector objectPosition)
        {
            Steering.MoveFrom(agentPosition, objectPosition, AgentSpeed, AvoidDistance);

            StayInWorld();
        }
Exemple #33
0
    public Steering GetSteering()
    {
        Steering steering = new Steering();

        float   shortestTime       = Mathf.Infinity;
        Agent   firstTarget        = null;
        float   firstMinSeparation = 0.0f;
        float   firstDistance      = 0.0f;
        Vector3 firstRelativePos   = Vector3.zero;
        Vector3 firstRelativeVel   = Vector3.zero;

        foreach (GameObject t in targets)
        {
            Agent target = t.GetComponent <Agent>();
            if (Vector3.Distance(target.position, npc.position) > 3f) //Addition
            {
                continue;
            }
            Vector3 relativePos   = target.position - npc.position;
            Vector3 relativeVel   = target.velocity - npc.velocity;
            float   relativeSpeed = relativeVel.magnitude;

            float timeToCollision = -(Vector3.Dot(relativePos, relativeVel))
                                    / (relativeSpeed * relativeSpeed);
            float distance      = relativePos.magnitude;
            float minSeparation = distance - (relativeSpeed * timeToCollision);
            if (minSeparation > 2 * collisionRadius)
            {
                continue;
            }

            if (timeToCollision > 0.0f && timeToCollision < shortestTime)
            {
                shortestTime       = timeToCollision;
                firstTarget        = target;
                firstMinSeparation = minSeparation;
                firstDistance      = distance;
                firstRelativePos   = relativePos;
                firstRelativeVel   = relativeVel;
            }
        }
        npc.GetComponent <Renderer>().material.color = Color.red;
        if (firstTarget == null)
        {
            return(steering);
        }
        if (firstMinSeparation <= 0.0f || firstDistance < 2 * collisionRadius)
        {
            firstRelativePos = firstTarget.position - npc.position; //This should be already assigned, so it is useless
            npc.GetComponent <Renderer>().material.color = Color.blue;
        }
        else
        {
            firstRelativePos += firstRelativeVel * shortestTime;
            npc.GetComponent <Renderer>().material.color = Color.green;
        }

        firstRelativePos.Normalize();
        steering.linear = -firstRelativePos * npc.MaxAccel;
        if (visibleRays)
        {
            drawRays(npc.position, steering.linear, Color.red);
        }
        return(steering);
    }
Exemple #34
0
 public Vector3 GetForce(Steering steering)
 {
     return(-SteeringUtilities.getSeekForce(steering, target));
 }
Exemple #35
0
        public override void Start()
        {
            base.Start();

            radioSpeakerName = TextManager.Get("Tutorial.Radio.Speaker");
            engineer         = Character.Controlled;

            var toolbox = engineer.Inventory.FindItemByIdentifier("toolbox");

            toolbox.Unequip(engineer);
            engineer.Inventory.RemoveItem(toolbox);

            var repairOrder = Order.GetPrefab("repairsystems");

            engineer_repairIcon      = repairOrder.SymbolSprite;
            engineer_repairIconColor = repairOrder.Color;

            var reactorOrder = Order.GetPrefab("operatereactor");

            engineer_reactorIcon      = reactorOrder.SymbolSprite;
            engineer_reactorIconColor = reactorOrder.Color;

            // Other tutorial items
            tutorial_securityFinalDoorLight = Item.ItemList.Find(i => i.HasTag("tutorial_securityfinaldoorlight")).GetComponent <LightComponent>();
            tutorial_mechanicFinalDoorLight = Item.ItemList.Find(i => i.HasTag("tutorial_mechanicfinaldoorlight")).GetComponent <LightComponent>();
            tutorial_submarineSteering      = Item.ItemList.Find(i => i.HasTag("command")).GetComponent <Steering>();

            tutorial_submarineSteering.CanBeSelected = false;
            foreach (ItemComponent ic in tutorial_submarineSteering.Item.Components)
            {
                ic.CanBeSelected = false;
            }

            SetDoorAccess(null, tutorial_securityFinalDoorLight, false);
            SetDoorAccess(null, tutorial_mechanicFinalDoorLight, false);

            // Room 2
            engineer_equipmentObjectiveSensor = Item.ItemList.Find(i => i.HasTag("engineer_equipmentobjectivesensor")).GetComponent <MotionSensor>();
            engineer_equipmentCabinet         = Item.ItemList.Find(i => i.HasTag("engineer_equipmentcabinet")).GetComponent <ItemContainer>();
            engineer_firstDoor      = Item.ItemList.Find(i => i.HasTag("engineer_firstdoor")).GetComponent <Door>();
            engineer_firstDoorLight = Item.ItemList.Find(i => i.HasTag("engineer_firstdoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(engineer_firstDoor, engineer_firstDoorLight, false);

            // Room 3
            engineer_reactorObjectiveSensor = Item.ItemList.Find(i => i.HasTag("engineer_reactorobjectivesensor")).GetComponent <MotionSensor>();
            tutorial_oxygenGenerator        = Item.ItemList.Find(i => i.HasTag("tutorial_oxygengenerator")).GetComponent <Powered>();
            engineer_reactor                       = Item.ItemList.Find(i => i.HasTag("engineer_reactor")).GetComponent <Reactor>();
            engineer_reactor.FireDelay             = engineer_reactor.MeltdownDelay = float.PositiveInfinity;
            engineer_reactor.FuelConsumptionRate   = 0.0f;
            engineer_reactor.OnOffSwitch.BarScroll = 1f;
            reactorOperatedProperly                = false;

            engineer_secondDoor      = Item.ItemList.Find(i => i.HasTag("engineer_seconddoor")).GetComponent <Door>();;
            engineer_secondDoorLight = Item.ItemList.Find(i => i.HasTag("engineer_seconddoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(engineer_secondDoor, engineer_secondDoorLight, false);

            // Room 4
            engineer_repairJunctionBoxObjectiveSensor = Item.ItemList.Find(i => i.HasTag("engineer_repairjunctionboxobjectivesensor")).GetComponent <MotionSensor>();
            engineer_brokenJunctionBox = Item.ItemList.Find(i => i.HasTag("engineer_brokenjunctionbox"));
            engineer_thirdDoor         = Item.ItemList.Find(i => i.HasTag("engineer_thirddoor")).GetComponent <Door>();
            engineer_thirdDoorLight    = Item.ItemList.Find(i => i.HasTag("engineer_thirddoorlight")).GetComponent <LightComponent>();

            engineer_brokenJunctionBox.Indestructible = false;
            engineer_brokenJunctionBox.Condition      = 0f;

            SetDoorAccess(engineer_thirdDoor, engineer_thirdDoorLight, false);

            // Room 5
            engineer_disconnectedJunctionBoxObjectiveSensor = Item.ItemList.Find(i => i.HasTag("engineer_disconnectedjunctionboxobjectivesensor")).GetComponent <MotionSensor>();

            engineer_disconnectedJunctionBoxes    = new PowerTransfer[4];
            engineer_disconnectedConnectionPanels = new ConnectionPanel[4];

            for (int i = 0; i < engineer_disconnectedJunctionBoxes.Length; i++)
            {
                engineer_disconnectedJunctionBoxes[i]           = Item.ItemList.Find(item => item.HasTag($"engineer_disconnectedjunctionbox_{i + 1}")).GetComponent <PowerTransfer>();
                engineer_disconnectedConnectionPanels[i]        = engineer_disconnectedJunctionBoxes[i].Item.GetComponent <ConnectionPanel>();
                engineer_disconnectedConnectionPanels[i].Locked = false;

                for (int j = 0; j < engineer_disconnectedJunctionBoxes[i].PowerConnections.Count; j++)
                {
                    foreach (Wire wire in engineer_disconnectedJunctionBoxes[i].PowerConnections[j].Wires)
                    {
                        if (wire == null)
                        {
                            continue;
                        }
                        wire.Locked = true;
                    }
                }
            }

            engineer_wire_1             = Item.ItemList.Find(i => i.HasTag("engineer_wire_1"));
            engineer_wire_1.SpriteColor = Color.Transparent;
            engineer_wire_2             = Item.ItemList.Find(i => i.HasTag("engineer_wire_2"));
            engineer_wire_2.SpriteColor = Color.Transparent;
            engineer_lamp_1             = Item.ItemList.Find(i => i.HasTag("engineer_lamp_1")).GetComponent <Powered>();
            engineer_lamp_2             = Item.ItemList.Find(i => i.HasTag("engineer_lamp_2")).GetComponent <Powered>();
            engineer_fourthDoor         = Item.ItemList.Find(i => i.HasTag("engineer_fourthdoor")).GetComponent <Door>();
            engineer_fourthDoorLight    = Item.ItemList.Find(i => i.HasTag("engineer_fourthdoorlight")).GetComponent <LightComponent>();
            SetDoorAccess(engineer_fourthDoor, engineer_fourthDoorLight, false);

            // Room 6
            engineer_workingPump = Item.ItemList.Find(i => i.HasTag("engineer_workingpump")).GetComponent <Pump>();
            engineer_workingPump.Item.CurrentHull.WaterVolume += engineer_workingPump.Item.CurrentHull.Volume;
            engineer_workingPump.IsActive = true;
            tutorial_lockedDoor_1         = Item.ItemList.Find(i => i.HasTag("tutorial_lockeddoor_1")).GetComponent <Door>();
            SetDoorAccess(tutorial_lockedDoor_1, null, true);

            // Submarine
            tutorial_submarineDoor      = Item.ItemList.Find(i => i.HasTag("tutorial_submarinedoor")).GetComponent <Door>();
            tutorial_submarineDoorLight = Item.ItemList.Find(i => i.HasTag("tutorial_submarinedoorlight")).GetComponent <LightComponent>();
            SetDoorAccess(tutorial_submarineDoor, tutorial_submarineDoorLight, true);

            tutorial_enteredSubmarineSensor = Item.ItemList.Find(i => i.HasTag("tutorial_enteredsubmarinesensor")).GetComponent <MotionSensor>();
            engineer_submarineJunctionBox_1 = Item.ItemList.Find(i => i.HasTag("engineer_submarinejunctionbox_1"));
            engineer_submarineJunctionBox_2 = Item.ItemList.Find(i => i.HasTag("engineer_submarinejunctionbox_2"));
            engineer_submarineJunctionBox_3 = Item.ItemList.Find(i => i.HasTag("engineer_submarinejunctionbox_3"));
            engineer_submarineReactor       = Item.ItemList.Find(i => i.HasTag("engineer_submarinereactor")).GetComponent <Reactor>();
            engineer_submarineReactor.OnOffSwitch.BarScrollValue = .25f;
            engineer_submarineReactor.IsActive = engineer_submarineReactor.AutoTemp = false;

            engineer_submarineJunctionBox_1.Indestructible = false;
            engineer_submarineJunctionBox_1.Condition      = 0f;
            engineer_submarineJunctionBox_2.Indestructible = false;
            engineer_submarineJunctionBox_2.Condition      = 0f;
            engineer_submarineJunctionBox_3.Indestructible = false;
            engineer_submarineJunctionBox_3.Condition      = 0f;
        }
    // Update is called once per frame
    protected virtual void Update()
    {
        if (steeringCalculate == null)
        {
        //			print("trying");
            steeringCalculate = new SteeringCalculateWeightedSum();
        }

        // combined steering force from steering behavior
        Vector2 steeringForce = steeringCalculate.CalculateSteering(this);

        Vector2 acceleration = steeringForce / mass; // acceleration = force / mass

        // update velocity
        velocity += acceleration * Time.deltaTime * TimeController.GameSpeed;

        // make sure it does not exceed maximum velocity ------------- ENABLE THIS LATER
        velocity = truncateSpeed (velocity);

        position += velocity * Time.deltaTime * TimeController.GameSpeed; // update position

        // update the heading if we have a very small velocity
        if (velocity.magnitude > 0.00001)
        {
            heading = velocity.normalized;
            tf.forward = new Vector3(heading.x, 0, heading.y);
        //			side = heading.	 ------------ MIGHT NEED IMPLEMENT SIDE LATER
        }

        if (steering == null)
        {
        //			print("trying");
            steering = new Steering(this, steeringCalculate);
        }

        //if (flee) { steering.Flee (targetVehicle); flee = false; } // TEMPORARY
        //if (pursuit) { steering.Pursuit (targetVehicle); flee = false; } // TEMPORARY
        //if (arrive) { steering.Arrive (new Vector2(targetVehicle.transform.position.x, targetVehicle.transform.position.z)); arrive = false; } // TEMPORARY

        // don't forget steering update
        steering.ManualUpdate();
    }
    void init()
    {
        if (Agent)
            AgentSteer = Agent.GetComponent<Steering>();

        AgentsList = new List<Steering>();

        Transform agentsTrans = GameObject.Find(AgentsName).transform;

        AgentsCount = agentsTrans.childCount;

        for (int i = 0; i < AgentsCount; ++i)
        {
            AgentsList.Add(agentsTrans.GetChild(i).GetComponent<Steering>());
        }

        ObstacleList = new List<Obstacle>();

        Transform obstacleTrans = GameObject.Find(ObstaclesName).transform;
        ObstacleCount = obstacleTrans.childCount;

        for (int i = 0; i < ObstacleCount; ++i)
        {
            ObstacleList.Add(obstacleTrans.GetChild(i).GetComponent<Obstacle>());
        }

        Application.targetFrameRate = -1;
    }
Exemple #38
0
    void Awake()
    {
        steeringBasics = GetComponent <Steering>();

        rb = GetComponent <AIRigidbody>();
    }
Exemple #39
0
        void OnEnable()
        {
            vehicle = transform.GetComponentInParent <Vehicle>();
            root    = vehicle.transform;

            wheelPivot = transform.parent;
            #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                if (!body)
                {
                    GameObject wheel     = new GameObject(name + "_Joint");
                    GameObject wheelTurn = null;
                    if (wheelPivot.name.Contains("WheelTurn"))
                    {
                        wheelTurn = new GameObject(name + "_Turn_Joint");
                        steering  = root.GetComponentInChildren <Steering>();
                    }


                    Transform physics = root.Find("Physics");
                    if (!physics)
                    {
                        physics                      = new GameObject("Physics").transform;
                        physics.parent               = root.transform;
                        physics.position             = root.position;
                        physics.transform.localScale = Vector3.one;
                    }

                    wheel.transform.parent   = physics;
                    wheel.transform.position = transform.position;
                    wheel.transform.rotation = root.rotation;

                    if (wheelTurn)
                    {
                        wheelTurn.transform.parent   = physics;
                        wheelTurn.transform.position = wheelPivot.position;
                        lineralDamper = GetComponentInParent <Absorber>();
                        if (!lineralDamper.name.Contains("LineralAbsorber"))
                        {
                            lineralDamper = null;
                        }
                        if (lineralDamper)
                        {
                            wheelTurn.transform.LookAt(wheelTurn.transform.position + steering.transform.up, -steering.transform.forward);
                        }
                        else
                        {
                            wheelTurn.transform.rotation = root.rotation;
                        }
                    }

                    joint        = wheel.AddComponent <HingeJoint>();
                    bodyCollider = wheel.AddComponent <MeshCollider>();
                    body         = wheel.GetComponent <Rigidbody>();

                    PhysicMaterial physicMaterial = (PhysicMaterial)AssetDatabase.LoadAssetAtPath("Assets/Vehicles/WheelSystem/PhysicsMaterials/Wheel.physicMaterial", typeof(PhysicMaterial));

                    parameters   = new Parameters(name, true, true, 2.0f, 0.0f, 0.0f, physicMaterial);
                    joint.anchor = Vector3.zero;
                    joint.axis   = Vector3.right;

                    if (wheelTurn)
                    {
                        turnJoint        = wheelTurn.AddComponent <HingeJoint>();
                        turnBody         = wheelTurn.GetComponent <Rigidbody>();
                        turnBody.mass    = parameters.mass;
                        turnJoint.anchor = Vector3.zero;
                        turnJoint.axis   = Vector3.up;

                        UpdateSteeringParameters();
                    }

                    if (!turnJoint)
                    {
                        Absorber aAbsorber = transform.GetComponentInParent <Absorber>();
                        if (aAbsorber)
                        {
                            connectedBody = aAbsorber.body;
                            absorber      = aAbsorber.transform;
                        }
                        else
                        {
                            connectedBody = root.GetComponent <Rigidbody>();
                            absorber      = root;
                        }
                    }
                    else
                    {
                        Absorber aAbsorber = transform.GetComponentInParent <Absorber>();
                        if (aAbsorber)
                        {
                            turnJoint.connectedBody = aAbsorber.body;
                            absorber = aAbsorber.transform;
                        }
                        else
                        {
                            turnJoint.connectedBody = root.GetComponent <Rigidbody>();
                            absorber = root;
                        }
                        connectedBody = turnBody;
                    }

                    joint.connectedBody = connectedBody;

                    //absorber = connectedBody.transform;

                    horsepower           = 10.0f;
                    maxVelocityMPS       = 55.0f;
                    newtonMeterPerSecond = 746.0f * horsepower;
                    tractionForce        = newtonMeterPerSecond / maxVelocityMPS;
                    CalculateCollider();
                }
            }
            else
            {
            #endif
            if (!absorber)
            {
                enabled = false;
                return;
            }
            newtonMeterPerSecond = 746.0f * horsepower;
            tractionForce        = newtonMeterPerSecond / maxVelocityMPS;
            radius = 0.5f * body.transform.lossyScale.y;
            body.maxAngularVelocity = maxVelocityMPS / radius;

            JointMotor motor = new JointMotor();
            motor.targetVelocity = (180.0f / Mathf.PI) * velocityMPS / radius;
            motor.force          = tractionForce * radius;;
            joint.motor          = motor;

            Absorber aAbsorber = transform.GetComponentInParent <Absorber>();

            if (aAbsorber)
            {
                aAbsorber.OnUpdade += OnUpdade;
            }
            else if (vehicle)
            {
                vehicle.OnUpdade += OnUpdade;
            }

            if (connectedBody)
            {
                localPosition     = VectorOperator.getLocalPosition(absorber, wheelPivot.position);
                wheelPivot.parent = root;
            }
            foreach (var item in root.GetComponentsInChildren <Collider>())
            {
                Physics.IgnoreCollision(bodyCollider, item);
            }

                #if UNITY_EDITOR
        }
                #endif
        }
Exemple #40
0
 public void SetSteering(Steering _steering)
 {
     this.steering = _steering;
 }
        /// <summary>
        /// Causes the agent to make one step towards the object at objectPosition
        /// The speed of approach will reduce one this agent is within
        /// an ApproachRadius of the objectPosition
        /// </summary>
        /// <param name="agentToApproach"></param>
        public void Approach(SOFT152Vector objectPosition)
        {
            Steering.MoveTo(agentPosition, objectPosition, AgentSpeed, ApproachRadius);

            StayInWorld();
        }
    private void Update()
    {
        Vector3 position   = transform.position;
        Vector3 target     = targetPos.position;
        bool    isSteering = GlobalSettings.isInSteering;

        if (rb.velocity.magnitude <= slowSpeed)
        {
            // print("we slow");
            // A
            if (Vector3.Distance(position, target) <= closeDistance)
            {
                // print("we close");
                //A i) behaviour

                //move to target, no turning
                if (!isSteering)
                {
                    Kinematic.Arrive(rb, transform, targetPos.position, closeSpeed);
                }
                else
                {
                    Steering.Arrive(rb, transform, targetPos.position, closeAcceleration, closeSpeed);
                }
            }
            else
            {
                // print("we far");
                //A ii) behaviour

                //if angle btw forward and target close to 0,
                if (Vector3.Angle(transform.forward, target - position) <= 2f)
                {
                    // then move forward
                    if (!isSteering)
                    {
                        Kinematic.Arrive(rb, transform, targetPos.position, farSpeed);
                    }
                    else
                    {
                        Steering.Arrive(rb, transform, targetPos.position, farAcceleration, farSpeed);
                    }
                }
                else
                {
                    // else turn towards target
                    if (isSteering || rb.velocity.magnitude < 1f)
                    {
                        Helper.Alignment(transform, target - position, stopRotationSpeed);
                    }
                    else
                    {
                        Helper.Alignment(transform, rb.velocity, stopRotationSpeed);
                    }
                }
            }
        }
        else
        {
            // print("we fast");
            //B
            // check arc infront of character
            float coneAngle = Helper.Map(rb.velocity.magnitude, 0f, farSpeed, fastAngle, slowAngle);
            if (Vector3.Angle(transform.forward, target - position)
                <= coneAngle)
            {
                // print("OhISee");
                //B i)
                if (!isSteering)
                {
                    Kinematic.Arrive(rb, transform, targetPos.position, farSpeed);
                }
                else
                {
                    Steering.Arrive(rb, transform, targetPos.position, farAcceleration, farSpeed);
                }
                Helper.Alignment(transform, rb.velocity, moveRotationSpeed);
            }
            else
            {
                // print("OhImBlind");
                // B ii)
                rb.velocity = Vector3.zero; //stop
                Helper.Alignment(transform, target - position, stopRotationSpeed);
            }
        }
    }
        /// <summary>
        /// Causes the agent to make one random step.
        /// The size of the step determined by the value of WanderLimits
        /// and the agents speed
        /// </summary>
        public void Wander()
        {
            Steering.Wander(agentPosition, wanderPosition, WanderLimits, AgentSpeed, randomNumberGenerator);

            StayInWorld();
        }
Exemple #44
0
 // Start is called before the first frame update
 void Start()
 {
     velocity     = Vector3.zero;
     steer        = new Steering();
     trueMaxSpeed = maxSpeed;
 }
Exemple #45
0
 public void DeregisterSteering(Steering steering)
 {
     _allSteerings.Remove(steering);
 }
Exemple #46
0
 public void SetSteering(Steering steer, float weight)
 {
     this.steer.linear  += (weight * steer.linear);
     this.steer.angular += (weight * steer.angular);
 }
Exemple #47
0
 /** Generates a steering that dinamically aligns the orientation to face the target */
 public static Steering Face(Kinematic source, Steering sourceSteering, ILocation target, AlignOptions opts)
 {
     return(Dynamic.Align(source, sourceSteering, Kinematic.Vec2Orient(target.position - source.position), opts));
 }
Exemple #48
0
 public static Steering ApplyPriority(Steering steering, float priority)
 {
     steering.linear  *= priority;
     steering.angular *= priority;
     return(steering);
 }
Exemple #49
0
 void Start()
 {
     velocity = Vector3.zero;
     steering = new Steering();
 }
Exemple #50
0
        public RespawnManager(NetworkMember networkMember, Submarine shuttle)
            : base(shuttle)
        {
            this.networkMember = networkMember;

            if (shuttle != null)
            {
                respawnShuttle = new Submarine(shuttle.FilePath, shuttle.MD5Hash.Hash, true);
                respawnShuttle.Load(false);

                ResetShuttle();

                //respawnShuttle.GodMode = true;

                shuttleDoors = new List <Door>();
                foreach (Item item in Item.ItemList)
                {
                    if (item.Submarine != respawnShuttle)
                    {
                        continue;
                    }

                    var steering = item.GetComponent <Steering>();
                    if (steering != null)
                    {
                        shuttleSteering = steering;
                    }

                    var door = item.GetComponent <Door>();
                    if (door != null)
                    {
                        shuttleDoors.Add(door);
                    }

                    //lock all wires to prevent the players from messing up the electronics
                    var connectionPanel = item.GetComponent <ConnectionPanel>();
                    if (connectionPanel != null)
                    {
                        foreach (Connection connection in connectionPanel.Connections)
                        {
                            foreach (Wire wire in connection.Wires)
                            {
                                if (wire != null)
                                {
                                    wire.Locked = true;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                respawnShuttle = null;
            }

#if SERVER
            if (networkMember is GameServer server)
            {
                respawnTimer     = server.ServerSettings.RespawnInterval;
                maxTransportTime = server.ServerSettings.MaxTransportTime;
            }
#endif
        }
        public override void Start()
        {
            base.Start();

            radioSpeakerName = TextManager.Get("Tutorial.Radio.Speaker");
            officer          = Character.Controlled;

            var handcuffs = FindOrGiveItem(officer, "handcuffs");

            handcuffs.Unequip(officer);
            officer.Inventory.RemoveItem(handcuffs);

            var stunbaton = FindOrGiveItem(officer, "stunbaton");

            stunbaton.Unequip(officer);
            officer.Inventory.RemoveItem(stunbaton);

            var smg = FindOrGiveItem(officer, "smg");

            smg.Unequip(officer);
            officer.Inventory.RemoveItem(smg);

            var divingknife = FindOrGiveItem(officer, "divingknife");

            divingknife.Unequip(officer);
            officer.Inventory.RemoveItem(divingknife);

            var steroids = FindOrGiveItem(officer, "steroids");

            steroids.Unequip(officer);
            officer.Inventory.RemoveItem(steroids);

            var ballistichelmet =
                officer.Inventory.FindItemByIdentifier("ballistichelmet1") ??
                officer.Inventory.FindItemByIdentifier("ballistichelmet2") ??
                FindOrGiveItem(officer, "ballistichelmet3");

            ballistichelmet.Unequip(officer);
            officer.Inventory.RemoveItem(ballistichelmet);

            var bodyarmor = FindOrGiveItem(officer, "bodyarmor");

            bodyarmor.Unequip(officer);
            officer.Inventory.RemoveItem(bodyarmor);

            var gunOrder = Order.GetPrefab("operateweapons");

            officer_gunIcon      = gunOrder.SymbolSprite;
            officer_gunIconColor = gunOrder.Color;

            var bandage = FindOrGiveItem(officer, "antibleeding1");

            bandage.Unequip(officer);
            officer.Inventory.RemoveItem(bandage);
            FindOrGiveItem(officer, "antibleeding1");

            // Other tutorial items
            tutorial_mechanicFinalDoorLight = Item.ItemList.Find(i => i.HasTag("tutorial_mechanicfinaldoorlight")).GetComponent <LightComponent>();
            tutorial_submarineSteering      = Item.ItemList.Find(i => i.HasTag("command")).GetComponent <Steering>();

            tutorial_submarineSteering.CanBeSelected = false;
            foreach (ItemComponent ic in tutorial_submarineSteering.Item.Components)
            {
                ic.CanBeSelected = false;
            }

            SetDoorAccess(null, tutorial_mechanicFinalDoorLight, false);

            // Room 2
            officer_equipmentObjectiveSensor = Item.ItemList.Find(i => i.HasTag("officer_equipmentobjectivesensor")).GetComponent <MotionSensor>();
            officer_equipmentCabinet         = Item.ItemList.Find(i => i.HasTag("officer_equipmentcabinet")).GetComponent <ItemContainer>();
            officer_firstDoor      = Item.ItemList.Find(i => i.HasTag("officer_firstdoor")).GetComponent <Door>();
            officer_firstDoorLight = Item.ItemList.Find(i => i.HasTag("officer_firstdoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(officer_firstDoor, officer_firstDoorLight, false);

            // Room 3
            officer_crawlerSensor   = Item.ItemList.Find(i => i.HasTag("officer_crawlerobjectivesensor")).GetComponent <MotionSensor>();
            officer_crawlerSpawnPos = Item.ItemList.Find(i => i.HasTag("officer_crawlerspawn")).WorldPosition;
            officer_secondDoor      = Item.ItemList.Find(i => i.HasTag("officer_seconddoor")).GetComponent <Door>();
            officer_secondDoorLight = Item.ItemList.Find(i => i.HasTag("officer_seconddoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(officer_secondDoor, officer_secondDoorLight, false);

            // Room 4
            officer_somethingBigSensor = Item.ItemList.Find(i => i.HasTag("officer_somethingbigobjectivesensor")).GetComponent <MotionSensor>();
            officer_coilgunLoader      = Item.ItemList.Find(i => i.HasTag("officer_coilgunloader")).GetComponent <ItemContainer>();
            officer_superCapacitor     = Item.ItemList.Find(i => i.HasTag("officer_supercapacitor")).GetComponent <PowerContainer>();
            officer_coilgunPeriscope   = Item.ItemList.Find(i => i.HasTag("officer_coilgunperiscope"));
            officer_hammerheadSpawnPos = Item.ItemList.Find(i => i.HasTag("officer_hammerheadspawn")).WorldPosition;
            officer_thirdDoor          = Item.ItemList.Find(i => i.HasTag("officer_thirddoor")).GetComponent <Door>();
            officer_thirdDoorLight     = Item.ItemList.Find(i => i.HasTag("officer_thirddoorlight")).GetComponent <LightComponent>();
            officer_ammoShelf_1        = Item.ItemList.Find(i => i.HasTag("officer_ammoshelf_1")).GetComponent <ItemContainer>();
            officer_ammoShelf_2        = Item.ItemList.Find(i => i.HasTag("officer_ammoshelf_2")).GetComponent <ItemContainer>();

            SetDoorAccess(officer_thirdDoor, officer_thirdDoorLight, false);

            // Room 5
            officer_rangedWeaponSensor  = Item.ItemList.Find(i => i.HasTag("officer_rangedweaponobjectivesensor")).GetComponent <MotionSensor>();
            officer_rangedWeaponCabinet = Item.ItemList.Find(i => i.HasTag("officer_rangedweaponcabinet")).GetComponent <ItemContainer>();
            officer_rangedWeaponHolder  = Item.ItemList.Find(i => i.HasTag("officer_rangedweaponholder")).GetComponent <ItemContainer>();
            officer_fourthDoor          = Item.ItemList.Find(i => i.HasTag("officer_fourthdoor")).GetComponent <Door>();
            officer_fourthDoorLight     = Item.ItemList.Find(i => i.HasTag("officer_fourthdoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(officer_fourthDoor, officer_fourthDoorLight, false);

            // Room 6
            officer_mudraptorObjectiveSensor = Item.ItemList.Find(i => i.HasTag("officer_mudraptorobjectivesensor")).GetComponent <MotionSensor>();
            officer_mudraptorSpawnPos        = Item.ItemList.Find(i => i.HasTag("officer_mudraptorspawn")).WorldPosition;
            tutorial_securityFinalDoor       = Item.ItemList.Find(i => i.HasTag("tutorial_securityfinaldoor")).GetComponent <Door>();
            tutorial_securityFinalDoorLight  = Item.ItemList.Find(i => i.HasTag("tutorial_securityfinaldoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(tutorial_securityFinalDoor, tutorial_securityFinalDoorLight, false);

            // Submarine
            tutorial_submarineDoor          = Item.ItemList.Find(i => i.HasTag("tutorial_submarinedoor")).GetComponent <Door>();
            tutorial_submarineDoorLight     = Item.ItemList.Find(i => i.HasTag("tutorial_submarinedoorlight")).GetComponent <LightComponent>();
            tutorial_enteredSubmarineSensor = Item.ItemList.Find(i => i.HasTag("tutorial_enteredsubmarinesensor")).GetComponent <MotionSensor>();
            officer_subAmmoBox_1            = Item.ItemList.Find(i => i.HasTag("officer_subammobox_1"));
            officer_subAmmoBox_2            = Item.ItemList.Find(i => i.HasTag("officer_subammobox_2"));
            officer_subLoader_1             = Item.ItemList.Find(i => i.HasTag("officer_subloader_1")).GetComponent <ItemContainer>();
            officer_subLoader_2             = Item.ItemList.Find(i => i.HasTag("officer_subloader_2")).GetComponent <ItemContainer>();
            officer_subSuperCapacitor_1     = Item.ItemList.Find(i => i.HasTag("officer_subsupercapacitor_1")).GetComponent <PowerContainer>();
            officer_subSuperCapacitor_2     = Item.ItemList.Find(i => i.HasTag("officer_subsupercapacitor_2")).GetComponent <PowerContainer>();
            officer_subAmmoShelf            = Item.ItemList.Find(i => i.HasTag("officer_subammoshelf")).GetComponent <ItemContainer>();
            SetDoorAccess(tutorial_submarineDoor, tutorial_submarineDoorLight, true);
        }
Exemple #52
0
 public void SetSteering(Steering steeringType)
 {
     steering = steeringType;
 }
Exemple #53
0
 protected Szenario(int pId, string pType, string pCommand, string pMode, List <App> pApps, List <Robot> pRobots, Steering pSteering)
 {
     this.id       = pId;
     this.type     = pType;
     this.command  = pCommand;
     this.mode     = pMode;
     this.apps     = pApps;
     this.robots   = pRobots;
     this.steering = pSteering;
 }
        public override void Start()
        {
            base.Start();

            radioSpeakerName = TextManager.Get("Tutorial.Radio.Speaker");
            mechanic         = Character.Controlled;

            var toolbelt = FindOrGiveItem(mechanic, "toolbelt");

            toolbelt.Unequip(mechanic);
            mechanic.Inventory.RemoveItem(toolbelt);

            var crowbar = FindOrGiveItem(mechanic, "crowbar");

            crowbar.Unequip(mechanic);
            mechanic.Inventory.RemoveItem(crowbar);

            var repairOrder = Order.GetPrefab("repairsystems");

            mechanic_repairIcon      = repairOrder.SymbolSprite;
            mechanic_repairIconColor = repairOrder.Color;
            mechanic_weldIcon        = new Sprite("Content/UI/MainIconsAtlas.png", new Rectangle(1, 256, 127, 127), new Vector2(0.5f, 0.5f));

            // Other tutorial items
            tutorial_securityFinalDoorLight = Item.ItemList.Find(i => i.HasTag("tutorial_securityfinaldoorlight")).GetComponent <LightComponent>();
            tutorial_upperFinalDoor         = Item.ItemList.Find(i => i.HasTag("tutorial_upperfinaldoor")).GetComponent <Door>();
            tutorial_submarineSteering      = Item.ItemList.Find(i => i.HasTag("command")).GetComponent <Steering>();

            tutorial_submarineSteering.CanBeSelected = false;
            foreach (ItemComponent ic in tutorial_submarineSteering.Item.Components)
            {
                ic.CanBeSelected = false;
            }

            SetDoorAccess(null, tutorial_securityFinalDoorLight, false);
            SetDoorAccess(tutorial_upperFinalDoor, null, false);

            // Room 1
            mechanic_firstDoor      = Item.ItemList.Find(i => i.HasTag("mechanic_firstdoor")).GetComponent <Door>();
            mechanic_firstDoorLight = Item.ItemList.Find(i => i.HasTag("mechanic_firstdoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(mechanic_firstDoor, mechanic_firstDoorLight, false);

            // Room 2
            mechanic_equipmentObjectiveSensor = Item.ItemList.Find(i => i.HasTag("mechanic_equipmentobjectivesensor")).GetComponent <MotionSensor>();
            mechanic_equipmentCabinet         = Item.ItemList.Find(i => i.HasTag("mechanic_equipmentcabinet")).GetComponent <ItemContainer>();
            mechanic_secondDoor      = Item.ItemList.Find(i => i.HasTag("mechanic_seconddoor")).GetComponent <Door>();
            mechanic_secondDoorLight = Item.ItemList.Find(i => i.HasTag("mechanic_seconddoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(mechanic_secondDoor, mechanic_secondDoorLight, false);

            // Room 3
            mechanic_weldingObjectiveSensor = Item.ItemList.Find(i => i.HasTag("mechanic_weldingobjectivesensor")).GetComponent <MotionSensor>();
            mechanic_workingPump            = Item.ItemList.Find(i => i.HasTag("mechanic_workingpump")).GetComponent <Pump>();
            mechanic_thirdDoor      = Item.ItemList.Find(i => i.HasTag("mechanic_thirddoor")).GetComponent <Door>();
            mechanic_thirdDoorLight = Item.ItemList.Find(i => i.HasTag("mechanic_thirddoorlight")).GetComponent <LightComponent>();
            mechanic_brokenWall_1   = Structure.WallList.Find(i => i.SpecialTag == "mechanic_brokenwall_1");
            //mechanic_ladderSensor = Item.ItemList.Find(i => i.HasTag("mechanic_laddersensor")).GetComponent<MotionSensor>();

            SetDoorAccess(mechanic_thirdDoor, mechanic_thirdDoorLight, false);
            mechanic_brokenWall_1.Indestructible = false;
            mechanic_brokenWall_1.SpriteColor    = Color.White;
            for (int i = 0; i < mechanic_brokenWall_1.SectionCount; i++)
            {
                mechanic_brokenWall_1.AddDamage(i, 85);
            }
            mechanic_brokenhull_1 = mechanic_brokenWall_1.Sections[0].gap.FlowTargetHull;

            // Room 4
            mechanic_craftingObjectiveSensor = Item.ItemList.Find(i => i.HasTag("mechanic_craftingobjectivesensor")).GetComponent <MotionSensor>();
            mechanic_deconstructor           = Item.ItemList.Find(i => i.HasTag("mechanic_deconstructor")).GetComponent <Deconstructor>();
            mechanic_fabricator      = Item.ItemList.Find(i => i.HasTag("mechanic_fabricator")).GetComponent <Fabricator>();
            mechanic_craftingCabinet = Item.ItemList.Find(i => i.HasTag("mechanic_craftingcabinet")).GetComponent <ItemContainer>();
            mechanic_fourthDoor      = Item.ItemList.Find(i => i.HasTag("mechanic_fourthdoor")).GetComponent <Door>();
            mechanic_fourthDoorLight = Item.ItemList.Find(i => i.HasTag("mechanic_fourthdoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(mechanic_fourthDoor, mechanic_fourthDoorLight, false);

            // Room 5
            mechanic_fifthDoor      = Item.ItemList.Find(i => i.HasTag("mechanic_fifthdoor")).GetComponent <Door>();
            mechanic_fifthDoorLight = Item.ItemList.Find(i => i.HasTag("mechanic_fifthdoorlight")).GetComponent <LightComponent>();
            mechanic_fireSensor     = Item.ItemList.Find(i => i.HasTag("mechanic_firesensor")).GetComponent <MotionSensor>();

            SetDoorAccess(mechanic_fifthDoor, mechanic_fifthDoorLight, false);

            // Room 6
            mechanic_divingSuitObjectiveSensor = Item.ItemList.Find(i => i.HasTag("mechanic_divingsuitobjectivesensor")).GetComponent <MotionSensor>();
            mechanic_divingSuitContainer       = Item.ItemList.Find(i => i.HasTag("mechanic_divingsuitcontainer")).GetComponent <ItemContainer>();
            for (int i = 0; i < mechanic_divingSuitContainer.Inventory.Items.Length; i++)
            {
                foreach (ItemComponent ic in mechanic_divingSuitContainer.Inventory.Items[i].Components)
                {
                    ic.CanBePicked = true;
                }
            }
            mechanic_oxygenContainer = Item.ItemList.Find(i => i.HasTag("mechanic_oxygencontainer")).GetComponent <ItemContainer>();
            for (int i = 0; i < mechanic_oxygenContainer.Inventory.Items.Length; i++)
            {
                foreach (ItemComponent ic in mechanic_oxygenContainer.Inventory.Items[i].Components)
                {
                    ic.CanBePicked = true;
                }
            }
            tutorial_mechanicFinalDoor      = Item.ItemList.Find(i => i.HasTag("tutorial_mechanicfinaldoor")).GetComponent <Door>();
            tutorial_mechanicFinalDoorLight = Item.ItemList.Find(i => i.HasTag("tutorial_mechanicfinaldoorlight")).GetComponent <LightComponent>();

            SetDoorAccess(tutorial_mechanicFinalDoor, tutorial_mechanicFinalDoorLight, false);

            // Room 7
            mechanic_brokenPump = Item.ItemList.Find(i => i.HasTag("mechanic_brokenpump")).GetComponent <Pump>();
            mechanic_brokenPump.Item.Indestructible = false;
            mechanic_brokenPump.Item.Condition      = 0;
            mechanic_brokenPump.CanBeSelected       = false;
            mechanic_brokenPump.Item.GetComponent <Repairable>().CanBeSelected = false;
            mechanic_brokenWall_2       = Structure.WallList.Find(i => i.SpecialTag == "mechanic_brokenwall_2");
            tutorial_submarineDoor      = Item.ItemList.Find(i => i.HasTag("tutorial_submarinedoor")).GetComponent <Door>();
            tutorial_submarineDoorLight = Item.ItemList.Find(i => i.HasTag("tutorial_submarinedoorlight")).GetComponent <LightComponent>();

            mechanic_brokenWall_2.Indestructible = false;
            mechanic_brokenWall_2.SpriteColor    = Color.White;
            for (int i = 0; i < mechanic_brokenWall_2.SectionCount; i++)
            {
                mechanic_brokenWall_2.AddDamage(i, 85);
            }
            mechanic_brokenhull_2 = mechanic_brokenWall_2.Sections[0].gap.FlowTargetHull;
            SetDoorAccess(tutorial_submarineDoor, tutorial_submarineDoorLight, false);

            // Submarine
            tutorial_enteredSubmarineSensor = Item.ItemList.Find(i => i.HasTag("tutorial_enteredsubmarinesensor")).GetComponent <MotionSensor>();
            mechanic_submarineEngine        = Item.ItemList.Find(i => i.HasTag("mechanic_submarineengine")).GetComponent <Engine>();
            mechanic_submarineEngine.Item.Indestructible = false;
            mechanic_submarineEngine.Item.Condition      = 0f;
            mechanic_ballastPump_1 = Item.ItemList.Find(i => i.HasTag("mechanic_ballastpump_1")).GetComponent <Pump>();
            mechanic_ballastPump_1.Item.Indestructible = false;
            mechanic_ballastPump_1.Item.Condition      = 0f;
            mechanic_ballastPump_2 = Item.ItemList.Find(i => i.HasTag("mechanic_ballastpump_2")).GetComponent <Pump>();
            mechanic_ballastPump_2.Item.Indestructible = false;
            mechanic_ballastPump_2.Item.Condition      = 0f;
        }
Exemple #55
0
        public override Steering GetSteering()
        {
            // 用于计算周围所有Agent的距离和速度
            float      shortestTime       = Mathf.Infinity; // 保存最小碰撞时间
            GameObject firstTarget        = null;
            float      firstMinSeparation = 0.0f;
            float      firstDistance      = 0.0f;
            Vector3    firstRelativePos   = Vector3.zero; // 与最先碰撞对象的相对位置
            Vector3    firstRelativeVel   = Vector3.zero; // 与最先碰撞对象的相对速度

            for (int i = 0; i < targets.Length; ++i)
            {
                Agent   targetAgent   = agents[i];
                Vector3 relativePos   = targets[i].transform.position - transform.position;
                Vector3 relativeVel   = targetAgent.velocity - agent.velocity;
                float   relativeSpeed = relativeVel.magnitude;
                // 相对距离与相对方向的点积,得到相对方向上的移动距离 * 相对速度的值
                // 因此需要除以两次相对速度的值得到碰撞时间
                float timeToCollision = Vector3.Dot(relativePos, relativeVel);
                timeToCollision /= relativeSpeed * relativeSpeed * -1;

                // 相对移动的结果 使得两者之间的距离小于2 * collisionRadius时 才继续
                float distance      = relativePos.magnitude;
                float minSeparation = distance - relativeSpeed * timeToCollision;
                if (minSeparation > 2 * collisionRadius)
                {
                    continue;
                }

                // 更新数据
                if (timeToCollision > 0.0f && timeToCollision < shortestTime)
                {
                    shortestTime       = timeToCollision;
                    firstTarget        = targets[i];
                    firstMinSeparation = minSeparation;
                    firstDistance      = distance;
                    firstRelativePos   = relativePos;
                    firstRelativeVel   = relativeVel;
                }

                if (firstTarget == null)
                {
                    return(null);
                }

                Steering steering = new Steering();

                if (firstMinSeparation <= 0.0f || firstDistance < 2 * collisionRadius)
                {
                    firstRelativePos = firstTarget.transform.position;      // 说明对方在相对移动的方向上,那么位移方向就是对方的方向
                }
                else
                {
                    firstRelativePos += firstRelativeVel * shortestTime;    // 得到自身碰撞需要的位移方向
                }
                firstRelativePos.Normalize();

                steering.linear = -firstRelativePos * agent.maxAccel;       // 往反方向移动 避开碰撞
                return(steering);
            }
            return(base.GetSteering());
        }
 public SteeringTests()
 {
     _graph    = new Graph(_realGrid);
     _steering = new Steering(new Marcle15_Pathfinder());
 }
Exemple #57
0
    // Use this for initialization
    void Start()
    {
        myCharacterController = gameObject.GetComponent<CharacterController>();
        steerer = gameObject.GetComponent<Steering>();
        steerer.Radius = 5.0f;
        moveDirection = transform.forward;

        obstacles = GameObject.FindGameObjectsWithTag("Obstacle");
        distances = new float[obstacles.Length];

        minMax[0] = 92.0f;
        minMax[1] = 222.0f;
        minMax[2] = 20.0f;
        minMax[3] = 380.0f;
    }
    /* following the lead boid and raycasting to avoid obstacles for part 3 */
    public Steering followAndRaycast()
    {
        // structure to hold our steering for following the lead boid
        Steering steering = new Steering {
            linear  = Vector3.zero,
            angular = 0f
        };
        // structure to hold our steering for raycasting with obstacle avoidance
        Steering avoidance = new Steering {
            linear  = Vector3.zero,
            angular = 0f
        };

        // have boids pursue main boid following path
        steering.linear   = Arrive() * 1.1f;
        steering.angular  = Face() * 1.5f;
        steering.linear  += 6.75f * computeSeparation() + 0.45f * computeCohesion() + 0.36f * computeAlign().linear;
        steering.angular += computeAlign().angular * 0.5f;


        // CHECK FOR OBSTACLE AVOIDANCE
        // rays forward, to the left angle, and to the right angle
        RaycastHit hit;
        RaycastHit leftWhisker;
        RaycastHit rightWhisker;
        Vector3    rayStartPos     = agent.transform.position;
        float      avoidMultiplier = 0f;
        // check for a collision forward ...
        Vector3 rayVec = Quaternion.Euler(0f, agent.rotation, 0f) * agent.transform.forward;

        if (Physics.SphereCast(rayStartPos, 0.25f, rayVec, out hit, 5f))
        {
            // for visual
            Debug.DrawRay(rayStartPos, rayVec, Color.blue, Time.deltaTime);
            // create a target
            Vector3 avoidTarget = hit.point + hit.normal * avoidDistance;
            // delegate to seek
            Vector3 direction = avoidTarget - agent.position;
            direction.Normalize();
            direction        *= maxAcceleration;
            avoidance.linear += direction;
            // if to close, need to move further away
            if (hit.distance < 2f)
            {
                // only want to have a greater avoidance if its an obstacle
                if (hit.collider.gameObject.tag == "obstacle")
                {
                    avoidMultiplier += 1.5f;
                }
                // align to avoidance direction
                avoidance.angular += Align(avoidTarget);
            }
        }
        // check for a collision at a left angle ...
        Vector3 rightRayVec = Quaternion.Euler(0f, agent.rotation + 35f, 0f) * agent.transform.forward;

        if (Physics.SphereCast(rayStartPos, 0.05f, rightRayVec, out rightWhisker, 3f))
        {
            // for visual
            Debug.DrawRay(rayStartPos, rightRayVec, Color.magenta, Time.deltaTime);
            // create a target
            Vector3 avoidTarget = rightWhisker.point + hit.normal * avoidDistance;
            // delegate to seek and add to overall avoidance
            Vector3 direction = avoidTarget - agent.position;
            direction.Normalize();
            direction        *= maxAcceleration;
            avoidance.linear += direction;
            // if to close, need to move further away
            if (rightWhisker.distance < 2f)
            {
                // only want to have a greater avoidance if its an obstacle
                if (rightWhisker.collider.gameObject.tag == "obstacle")
                {
                    avoidMultiplier += 1f;
                }
                // align to avoidance direction
                avoidance.angular += Align(avoidTarget);
            }
        }

        // check for a collision at a right angle ...
        Vector3 leftRayVec = Quaternion.Euler(0f, agent.rotation - 35f, 0f) * agent.transform.forward;

        if (Physics.SphereCast(rayStartPos, 0.05f, leftRayVec, out leftWhisker, 3f))
        {
            // for visual
            Debug.DrawRay(rayStartPos, leftRayVec, Color.yellow, Time.deltaTime);
            // create a target
            Vector3 avoidTarget = leftWhisker.point + hit.normal * avoidDistance;
            // delegate to seek and add to overall avoidance
            Vector3 direction = avoidTarget - agent.position;
            direction.Normalize();
            direction        *= maxAcceleration;
            avoidance.linear += direction;
            // if too close, need to move further away
            if (leftWhisker.distance < 2f)
            {
                // only want to have a greater avoidance if its an obstacle
                if (leftWhisker.collider.gameObject.tag == "obstacle")
                {
                    avoidMultiplier += 1f;
                }
                // align to avoidance direction
                avoidance.angular += Align(avoidTarget);
            }
        }
        // if we need avoidance, add to overall pathfinding behavior
        if (avoidance.linear != Vector3.zero)
        {
            if (avoidMultiplier != 0f)   // if we need greater avoidance
            {
                steering.angular += avoidance.angular * avoidMultiplier * 0.8f;
                steering.linear  += avoidance.linear * avoidMultiplier * 0.8f;
            }
            else     // else, scale and add to current steering
            {
                steering.angular += avoidance.angular * 0.7f;
                steering.linear  += avoidance.linear * 0.7f;
            }
        }


        return(steering);
    }
Exemple #59
0
    //Creation of Villager
    public void Start()
    {
        //get component references
        characterController = gameObject.GetComponent<CharacterController> ();
        steering = gameObject.GetComponent<Steering> ();

        leaderFollowBool = false;

        gameManager = GameManager.Instance;
    }
    public void FixedUpdate()
    {
        /* Path finding for part 3 in FixedUpdate(), updates NPCController at end */
        if (part3)
        {
            // structure to hold our steering for path following
            Steering steering = new Steering {
                linear  = Vector3.zero,
                angular = 0f
            };
            // structure to hold our steering for raycasting with obstacle avoidance
            Steering avoidance = new Steering {
                linear  = Vector3.zero,
                angular = 0f
            };
            float avoidMultiplier = 0f;
            // while we are travveling the path
            if (current < Path.Length)
            {
                // find the current position on the path
                nextNode         = Path[current].transform.position;
                steering.angular = Align(nextNode);
                // delegate to seek
                Vector3 seekVec = nextNode - agent.transform.position;
                if (seekVec.magnitude > maxAcceleration)
                {
                    seekVec = seekVec.normalized * maxAcceleration;
                }
                steering.linear = seekVec;
                /* ACCOUNT FOR FLOCKING */
                steering.linear += 2.6f * computeSeparation() + 0.15f * computeCohesion() + 0.2f * computeAlign().linear;

                /* CHECK FOR OBSTACLE AVOIDANCE */
                // rays forward, to the left angle, and to the right angle
                RaycastHit hit;
                RaycastHit leftWhisker;
                RaycastHit rightWhisker;
                Vector3    rayStartPos = agent.transform.position;
                // check for a collision forward ...
                Vector3 rayVec = Quaternion.Euler(0f, agent.rotation, 0f) * agent.transform.forward;
                if (Physics.SphereCast(rayStartPos, 0.25f, rayVec, out hit, 5f))
                {
                    // for visual
                    Debug.DrawRay(rayStartPos, rayVec, Color.blue, Time.deltaTime);
                    // create a target
                    Vector3 avoidTarget = hit.point + hit.normal * avoidDistance;
                    // delegate to seek
                    Vector3 direction = avoidTarget - agent.position;
                    direction.Normalize();
                    direction        *= maxAcceleration;
                    avoidance.linear += direction;
                    // if to close, need to move further away
                    if (hit.distance < 2.4f)
                    {
                        // only want to have a greater avoidance if its an obstacle
                        if (hit.collider.gameObject.tag == "obstacle")
                        {
                            avoidMultiplier += 1.5f;
                        }
                        // align to avoidance direction
                        avoidance.angular += Align(avoidTarget);
                    }
                }
                // check for a collision at a left angle ...
                Vector3 rightRayVec = Quaternion.Euler(0f, agent.rotation + 30f, 0f) * agent.transform.forward;
                if (Physics.SphereCast(rayStartPos, 0.05f, rightRayVec, out rightWhisker, 3f))
                {
                    // for visual
                    Debug.DrawRay(rayStartPos, rightRayVec, Color.magenta, Time.deltaTime);
                    // create a target
                    Vector3 avoidTarget = rightWhisker.point + hit.normal * avoidDistance;
                    // delegate to seek and add to overall avoidance
                    Vector3 direction = avoidTarget - agent.position;
                    direction.Normalize();
                    direction        *= maxAcceleration;
                    avoidance.linear += direction;
                    // if to close, need to move further away
                    if (rightWhisker.distance < 2f)
                    {
                        // only want to have a greater avoidance if its an obstacle
                        if (rightWhisker.collider.gameObject.tag == "obstacle")
                        {
                            avoidMultiplier += 0.5f;
                        }
                        // align to avoidance direction
                        avoidance.angular += Align(avoidTarget);
                    }
                }
                // check for a collision at a right angle ...
                Vector3 leftRayVec = Quaternion.Euler(0f, agent.rotation - 30f, 0f) * agent.transform.forward;
                if (Physics.SphereCast(rayStartPos, 0.05f, leftRayVec, out leftWhisker, 3f))
                {
                    // for visual
                    Debug.DrawRay(rayStartPos, leftRayVec, Color.yellow, Time.deltaTime);
                    // create a target
                    Vector3 avoidTarget = leftWhisker.point + hit.normal * avoidDistance;
                    // delegate to seek and add to overall avoidance
                    Vector3 direction = avoidTarget - agent.position;
                    direction.Normalize();
                    direction        *= maxAcceleration;
                    avoidance.linear += direction;
                    // if too close, need to move further away
                    if (leftWhisker.distance < 2f)
                    {
                        // only want to have a greater avoidance if its an obstacle
                        if (leftWhisker.collider.gameObject.tag == "obstacle")
                        {
                            avoidMultiplier += 0.5f;
                        }
                        // align to avoidance direction
                        avoidance.angular += Align(avoidTarget);
                    }
                }
                // if we need avoidance, add to overall pathfinding behavior
                if (avoidance.linear != Vector3.zero)
                {
                    if (avoidMultiplier != 0f)   // if we need greater avoidance
                    {
                        steering.angular += avoidance.angular * avoidMultiplier * 0.8f;
                        steering.linear  += avoidance.linear * avoidMultiplier * 0.8f;
                    }
                    else     // else, scale and add to current steering
                    {
                        steering.angular += avoidance.angular * 0.95f;
                        steering.linear  += avoidance.linear * 0.95f;
                    }
                }
                agent.DrawCircle(agent.position + agent.transform.forward * 1.7f, 0.5f);
                // update our agent movement
                agent.GetComponent <NPCController>().update(steering.linear, steering.angular, Time.deltaTime);
                // if we are close to destination point on path
                float distance = (agent.position - Path[current].transform.position).magnitude;
                if (distance <= 2.3f)
                {
                    // set next destination point
                    current += 1;
                }
            }
        }
    }