public override void StartSimulation()
    {
        base.StartSimulation();

        allomancer = GetComponentInChildren <NonPlayerPushPullController>();
        coin       = GetComponentInChildren <Magnetic>();
        coinWall   = transform.Find("CoinWall").GetComponent <Rigidbody>();
        alloWall   = transform.Find("AlloWall").GetComponent <Rigidbody>();

        counter = 0;
        cleared = false;

        allomancer.PushTargets.MaxRange = -1;
        allomancer.AddPushTarget(coin);
        texts = HUDSimulations.CoinWall.GetComponentsInChildren <Text>();

        texts[texts.Length - 8].text = "Wall: " + TextCodes.LightBlue("Anchored");
        texts[texts.Length - 7].text = "Allomancer: " + TextCodes.Gray("Unanchored");
        texts[texts.Length - 6].text = "Coin: " + TextCodes.Gray("Unanchored");
        texts[texts.Length - 5].text = "Wall: " + TextCodes.LightBlue("Anchored");

        if (SettingsMenu.settingsData.anchoredBoost == 1)
        {
            texts[texts.Length - 4].text = "Allomantic Normal Force";
            //Time.timeScale = 1f;
        }
        else if (SettingsMenu.settingsData.anchoredBoost == 2)
        {
            texts[texts.Length - 4].text = "Exponential w/ Velocity factor";
            //Time.timeScale = 1f;
        }
        else
        {
            texts[texts.Length - 4].text = "Distributed Power";
            //Time.timeScale = .2f;
        }
        // This is what messes up the DP's energy distribution
        //Time.fixedDeltaTime = Time.timeScale * 1 / 60f;

        if (SettingsMenu.settingsData.forceDistanceRelationship == 0)
        {
            texts[texts.Length - 9].text = "Linear Distance Relationship";
        }
        else if (SettingsMenu.settingsData.forceDistanceRelationship == 1)
        {
            texts[texts.Length - 9].text = "Inverse Square Distance Relationship";
        }
        else if (SettingsMenu.settingsData.forceDistanceRelationship == 2)
        {
            texts[texts.Length - 9].text = "Exponential w/ Distance Relationship";
        }

        texts[texts.Length - 3].text = "Time scale: " + HUD.RoundStringToSigFigs(Time.timeScale);
        texts[texts.Length - 2].text = "Allomancer mass: " + allomancer.Mass + "kg";
        texts[texts.Length - 1].text = "Coin mass: " + coin.MagneticMass + "kg";
    }
Esempio n. 2
0
    private void Update()
    {
        if (!PauseMenu.IsPaused)
        {
            //Debug.Log(facingPlayer + " . " + tracingPlayer + " > " + chasingPlayer + " > " + tracingPath + " > " + releasingPlayer);

            // Executes during Rising. Face the Spike towards the player, vertically.
            if (facingPlayer)
            {
                // Rotate Target towards Player
                Vector3 distancetoPlayer = spike.CenterOfMass - Player.PlayerIronSteel.CenterOfMass;
                float   angle            = 180 - Mathf.Atan2(distancetoPlayer.x, distancetoPlayer.z) * Mathf.Rad2Deg;

                //Vector3 newRotation = Quaternion.LookRotation(Player.PlayerIronSteel.CenterOfMass - spikeTarget.position).eulerAngles;
                //Vector3 newRotation = Quaternion.Slerp(spikeTarget.rotation, Quaternion.LookRotation(Player.PlayerIronSteel.CenterOfMass - spikeTarget.position), slerpConstantPlayer * Time.deltaTime).eulerAngles;
                Vector3 newRotation;
                newRotation.z = angle;
                newRotation.x = 90;
                newRotation.y = 0;
                //spikeTarget.eulerAngles = newRotation;
                spike.transform.eulerAngles = Quaternion.Slerp(spike.transform.rotation, Quaternion.Euler(newRotation), slerpConstantPlayer * Time.deltaTime).eulerAngles;
            }

            // Executes after Rising. The spike angles itself with the spike towards the player. Once the angle is somewhat low, it begins Pulling on the player.
            if (tracingPlayer)
            {
                Quaternion newRotation = Quaternion.Slerp(spike.transform.rotation, Quaternion.LookRotation(Player.PlayerIronSteel.CenterOfMass - spike.CenterOfMass), slerpConstantPlayer * Time.deltaTime * slerpTime);
                slerpTime = slerpTimeChargeupPlayer * (Mathf.Exp(-Time.time + startTime) + Time.time - startTime + 1);
                spike.transform.rotation = newRotation;
                //spike.transform.position = spikeTarget.transform.position;

                float angle = Quaternion.Angle(Quaternion.LookRotation(Player.PlayerIronSteel.CenterOfMass - spike.CenterOfMass), newRotation);
                if (angle < anglePullThreshold && spike.PullTargets.Count == 0)
                {
                    // add player as a pull target
                    spike.AddPullTarget(Player.PlayerMagnetic);
                    spike.IronPulling = true;
                    spike.IronBurnPercentageTarget = .2f;
                    spike.PullTargets.MaxRange     = -1;
                }
                if (angle < angleEqualThreshold)
                {
                    tracingPlayer = false;
                    chasingPlayer = true;
                    slerpTime     = 0;


                    spikeRb.isKinematic            = false;
                    spikeRb.drag                   = dragChasing;
                    spikeRb.velocity               = Vector3.zero;
                    spikeRb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
                    spike.IronBurnPercentageTarget = .75f;
                }
            }

            // The Spike begins chasing the player as it Pulls on the player.
            if (chasingPlayer)
            {
                Quaternion newRotation = Quaternion.LookRotation(Player.PlayerIronSteel.CenterOfMass - spike.CenterOfMass);
                spike.transform.rotation = newRotation;

                if ((Player.PlayerIronSteel.CenterOfMass - spike.CenterOfMass).magnitude < distanceThresholdSpiking)
                {
                    chasingPlayer = false;
                    spikingPlayer = true;

                    Player.CanControlPlayer = false;
                    Player.PlayerInstance.GetComponent <Rigidbody>().velocity = spikeRb.velocity;
                }
            }

            // The spike has touched the player. Freeze the player and keep pulling the spike into them.
            if (spikingPlayer)
            {
                //Quaternion newRotation = Quaternion.LookRotation(Player.PlayerIronSteel.CenterOfMass - spike.CenterOfMass);
                //spike.transform.rotation = newRotation;

                if ((Player.PlayerIronSteel.CenterOfMass - spike.CenterOfMass).magnitude < distanceThresholdEqual)
                {
                    spikingPlayer = false;
                    tracingPath   = true;

                    spikeRb.drag = dragTracing;

                    // Set Player constraint
                    Player.PlayerInstance.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;

                    // Make Spike Target rotate towards spline velocity
                    spikeTarget.transform.position = spike.transform.position;
                    spike.transform.localPosition  = Vector3.zero;
                    //spikeTarget.transform.rotation = spike.transform.rotation;
                    //spike.transform.localRotation = Quaternion.identity;
                    Player.PlayerInstance.transform.SetParent(spike.transform);
                    Player.PlayerInstance.transform.localPosition = Vector3.zero;

                    splineDragging.SetInitialPoint(transform.InverseTransformPoint(spike.transform.position), spikeRb.velocity.normalized);

                    spike.IronBurnPercentageTarget = 0;
                    spike.IronPulling = false;
                }
            }

            // Follow the Path.
            if (tracingPath)
            {
                progress += Time.deltaTime / animationTime * slerpTime;
                slerpTime = Mathf.Min(1, slerpTime + Time.deltaTime * slerpTimeChargeupPath);
                if (progress < 1f)
                {
                    // Change position of spike and childed player
                    splineDragging.FollowCurve(spikeTarget.transform, progress, false);

                    // If the spike was pulled away from its path, force the spike back towards the path
                    Vector3 distance    = spikeTarget.position - spike.CenterOfMass;
                    float   sqrDistance = distance.sqrMagnitude;
                    spikeRb.AddForce(forceConstantFar * distance.normalized * sqrDistance, ForceMode.Acceleration);

                    // Rotate the spike to follow the path, a few moments in the future
                    float offsetTime = progress + forwardTimeOffset / animationTime;
                    offsetTime = offsetTime > 1 ? 1 : offsetTime;
                    //Debug.Log("Distance: " + distance.magnitude);
                    //if (offsetTime < 1) {
                    //Vector3 velocity = splineDragging.GetVelocity(offsetTime);
                    //Quaternion newRotation = Quaternion.LookRotation(splineDragging.GetPoint(offsetTime) - spikeTarget.position);
                    Quaternion newRotation = Quaternion.Slerp(spike.transform.rotation, Quaternion.LookRotation(splineDragging.GetPoint(offsetTime) - spikeTarget.position), slerpConstantPath * Time.deltaTime * slerpTimeRotation);
                    spike.transform.rotation = newRotation;
                    //}

                    slerpTimeRotation = slerpTimeRotation + Time.deltaTime * slerpTimeChargeupPathRotation;
                }
                else
                {
                    tracingPath       = false;
                    releasingPlayer   = true;
                    slerpTime         = 0;
                    slerpTimeRotation = 0;
                    progress          = 0;

                    Player.CanControlPlayer = true;

                    Player.PlayerInstance.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
                    Player.PlayerInstance.transform.SetParent(GameObject.FindGameObjectWithTag("GameController").transform);

                    Player.PlayerInstance.GetComponent <Rigidbody>().velocity = splineDragging.GetVelocity(1);
                    Player.PlayerInstance.transform.position += splineDragging.GetVelocity(1) * Time.fixedDeltaTime;
                    spikeRb.velocity            = -splineDragging.GetVelocity(1);
                    spikeRb.transform.position -= splineDragging.GetVelocity(1) * Time.fixedDeltaTime;

                    spike.AddPushTarget(Player.PlayerMagnetic);
                    spike.SteelPushing = true;
                    spike.SteelBurnPercentageTarget = .5f;
                    spike.PushTargets.MaxRange      = 3;
                }
            }

            // Pushing the player off of the Spike.
            if (releasingPlayer)
            {
                if ((Player.PlayerIronSteel.CenterOfMass - spike.CenterOfMass).sqrMagnitude > .01)
                {
                    Quaternion newRotation = Quaternion.LookRotation(Player.PlayerIronSteel.CenterOfMass - spike.CenterOfMass);
                    //Quaternion newRotation = Quaternion.LookRotation(-spikeRb.velocity);
                    spike.transform.rotation = newRotation;
                }

                if ((spike.CenterOfMass - Player.PlayerIronSteel.CenterOfMass).magnitude > distanceThresholdReturn)
                {
                    releasingPlayer = false;
                    returningHome   = true;

                    spikeRb.collisionDetectionMode = CollisionDetectionMode.Discrete;
                    spikeTarget.transform.position = spike.transform.position;
                    spike.transform.localPosition  = Vector3.zero;
                    splineReturnHome.SetInitialPoint(transform.InverseTransformPoint(spike.transform.position), spikeRb.velocity.normalized);
                }
            }

            if (returningHome)
            {
                progress += Time.deltaTime / animationTime;
                if (progress < 1)
                {
                    splineReturnHome.FollowCurve(spikeTarget.transform, progress, false);

                    // If the spike was pulled away from its path, force the spike back towards the path
                    Vector3 distance    = spikeTarget.position - spike.CenterOfMass;
                    float   sqrDistance = distance.sqrMagnitude;
                    spikeRb.AddForce(forceConstantFar * distance.normalized * sqrDistance, ForceMode.Acceleration);

                    // Rotate the spike to follow the path, a few moments in the future
                    float offsetTime = progress + forwardTimeOffset / animationTime;
                    offsetTime = offsetTime > 1 ? 1 : offsetTime;

                    Vector3    velocity    = splineReturnHome.GetVelocity(offsetTime);
                    Quaternion newRotation = Quaternion.Slerp(spike.transform.rotation, Quaternion.LookRotation(splineReturnHome.GetPoint(offsetTime) - spikeTarget.position), slerpConstantPath * Time.deltaTime * slerpTimeRotation);
                    spike.transform.rotation = newRotation;

                    slerpTimeRotation = slerpTimeRotation + Time.deltaTime * slerpTimeChargeupPathReturn;
                }
                else
                {
                    returningHome = false;
                    anim.enabled  = true;

                    startTime         = 0;
                    slerpTime         = 0;
                    slerpTimeRotation = 0;
                    progress          = 0;

                    spikeRb.isKinematic = true;
                    anim.ResetTrigger("PlayerEntersHome");
                    anim.SetTrigger("Fall");
                }
            }
        }
    }
    public override void StartSimulation()
    {
        base.StartSimulation();

        allomancerTop    = transform.Find("AllomancerTop").GetComponent <NonPlayerPushPullController>();
        coinTop          = transform.Find("CoinTop").GetComponentInChildren <Magnetic>();
        allomancerBottom = transform.Find("AllomancerBottom").GetComponent <NonPlayerPushPullController>();
        coinBottom       = transform.Find("CoinBottom").GetComponentInChildren <Magnetic>();

        counter      = 0;
        groundHeight = transform.Find("CoinWall").transform.position.y + .5f;


        allomancerTop.PushTargets.MaxRange = -1;
        allomancerTop.AddPushTarget(coinTop);
        allomancerTop.SteelBurnPercentageTarget = 1;
        allomancerBottom.PushTargets.MaxRange   = -1;
        allomancerBottom.AddPushTarget(coinBottom);
        allomancerBottom.SteelBurnPercentageTarget = 1;

        texts = HUDSimulations.CoinGround.GetComponentsInChildren <Text>();

        if (SettingsMenu.settingsData.anchoredBoost == 1)
        {
            texts[texts.Length - 6].text = "Allomantic Normal Force";
        }
        else if (SettingsMenu.settingsData.anchoredBoost == 2)
        {
            texts[texts.Length - 6].text = "Exponential w/ Velocity factor";
            switch (SettingsMenu.settingsData.exponentialWithVelocitySignage)
            {
            case 0: {
                texts[texts.Length - 5].text = "Relationship 1 (Both Directions Decrease)";
                break;
            }

            case 1: {
                texts[texts.Length - 5].text = "Relationship 2/3 (Moving Towards Decreases)";
                break;
            }

            case 2: {
                texts[texts.Length - 5].text = "Relationship 3/4 (Moving Away Decreases)";
                break;
            }

            case 3: {
                texts[texts.Length - 5].text = "Relationship 6/7 (Symmetrical)";
                break;
            }
            }
        }
        else if (SettingsMenu.settingsData.anchoredBoost == 3)
        {
            texts[texts.Length - 6].text = "Distributed Power";
        }
        else
        {
            texts[texts.Length - 6].text = "No Anchored Boost";
        }

        if (SettingsMenu.settingsData.forceDistanceRelationship == 0)
        {
            texts[texts.Length - 4].text = "Linear Distance";
        }
        else if (SettingsMenu.settingsData.forceDistanceRelationship == 1)
        {
            texts[texts.Length - 4].text = "Inverse Square Distance";
        }
        else if (SettingsMenu.settingsData.forceDistanceRelationship == 2)
        {
            texts[texts.Length - 4].text = "Exponential w/ Distance";
        }

        texts[texts.Length - 3].text = "Time scale: " + HUD.RoundStringToSigFigs(Time.timeScale);
        texts[texts.Length - 2].text = "Allomancer mass: " + allomancerTop.Mass + "kg";
        texts[texts.Length - 1].text = "Coin mass: " + coinTop.MagneticMass + "kg";
    }