예제 #1
0
파일: Goal.cs 프로젝트: kkiniaes/TBT
    public void AddChildren()
    {
        if (children.Count == 0 && numElementsCombined > 1)
        {
            for (int i = 1; i < numElementsCombined; i++)
            {
                Goal child = Instantiate <Goal>(childPrefab);
                child.numElementsCombined  = i;
                child.hydrogenScale        = hydrogenScale;
                child.transform.localScale = hydrogenScale * Mathf.Sqrt(i);
                child.childPrefab          = childPrefab;
                child.Combine();

                children.Push(child);

                PhysicsModifyable pM = child.GetComponent <PhysicsModifyable>();
                while (LevelManager.instance.stateStacks.ContainsKey(pM))
                {
                    LevelManager.instance.stateStacks.Remove(pM);
                }
                Stack initStackState = new Stack();
                State initState      = State.GetState(pM);
                initStackState.Push(initState);
                LevelManager.instance.stateStacks.Add(pM, initStackState);
            }
        }
    }
예제 #2
0
 public static void TryAddPM(PhysicsModifyable pM)
 {
     if (!objs.Contains(pM))
     {
         objs.Add(pM);
     }
 }
예제 #3
0
파일: Goal.cs 프로젝트: kkiniaes/TBT
    // Use this for initialization
    void Start()
    {
        if (combineEffect == null)
        {
            combineEffect = Resources.Load <GameObject>("CombineEffect");
        }

        if (numElementsCombined > 1 && children.Count <= 0)
        {
            AddChildren();

            PhysicsModifyable pM = GetComponent <PhysicsModifyable>();
            while (LevelManager.instance.stateStacks.ContainsKey(pM))
            {
                LevelManager.instance.stateStacks.Remove(pM);
            }

            Stack initStackState = new Stack();
            State initState      = State.GetState(pM);
            initStackState.Push(initState);
            LevelManager.instance.stateStacks.Add(pM, initStackState);
        }

        transform.localScale = hydrogenScale * Mathf.Sqrt(numElementsCombined);
    }
예제 #4
0
    public static void UnBind(PhysicsModifyable pM1, PhysicsModifyable pM2)
    {
        PhysicsAffected pA1 = pM1.GetComponent <PhysicsAffected>();
        PhysicsAffected pA2 = pM2.GetComponent <PhysicsAffected>();

        if (pA1 != null && pA2 != null)
        {
            if (pA1.GetComponent <FixedJoint>() != null)
            {
                Destroy(pA1.GetComponent <FixedJoint>());
            }

            if (pA2.GetComponent <FixedJoint>() != null)
            {
                Destroy(pA2.GetComponent <FixedJoint>());
            }
        }
        else if (pA1 != null || pA2 != null)
        {
            if (pA1 != null)
            {
                pA1.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
            }
            else if (pA2 != null)
            {
                pA2.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
            }
        }
    }
예제 #5
0
    public static State GetState(PhysicsModifyable pM)
    {
        State myState = new State();

        myState.timeElapsed = Player.instance.TimeElapsed;
        myState.active      = pM.gameObject.activeSelf;
        if (pM.gameObject.activeSelf)
        {
            myState.mass      = pM.Mass;
            myState.charge    = pM.Charge;
            myState.entangled = pM.Entangled;

            PhysicsAffected pA = pM.GetComponent <PhysicsAffected>();
            if (pA != null)
            {
                myState.velocity        = pA.Velocity;
                myState.angularVelocity = pA.AngularVelocity;
                myState.position        = pA.Position;
                myState.rotation        = pA.Rotation;
            }
            else
            {
                myState.position = pM.Position;
                myState.rotation = pM.Rotation;
            }

            Goal g = pM.GetComponent <Goal>();
            if (g != null)
            {
                myState.combined            = g.Combined;
                myState.numElementsCombined = g.numElementsCombined;
                myState.children            = LevelManager.Clone(g.Children);
            }

            Switch[] switches = pM.GetComponents <Switch>();
            myState.activated = new bool[switches.Length];
            foreach (Switch s in switches)
            {
                myState.activated[s.SwitchIndex] = s.activated;
            }
        }

        return(myState);
    }
예제 #6
0
    public static void Bind(PhysicsModifyable pM1, PhysicsModifyable pM2)
    {
        PhysicsAffected pA1 = pM1.GetComponent <PhysicsAffected>();
        PhysicsAffected pA2 = pM2.GetComponent <PhysicsAffected>();

        if (pA1 != null && pA2 != null)
        {
            FixedJoint j1 = pA1.GetComponent <FixedJoint>();
            if (j1 == null || j1.connectedBody != pA2.GetComponent <Rigidbody>())
            {
                if (j1 != null)
                {
                    Destroy(j1);
                }

                j1 = pA1.gameObject.AddComponent <FixedJoint>();
                j1.connectedBody = pA2.GetComponent <Rigidbody>();
            }

            FixedJoint j2 = pA2.GetComponent <FixedJoint>();
            if (j2 == null || j2.connectedBody != pA1.GetComponent <Rigidbody>())
            {
                if (j2 != null)
                {
                    Destroy(j2);
                }

                j2 = pA2.gameObject.AddComponent <FixedJoint>();
                j2.connectedBody = pA1.GetComponent <Rigidbody>();
            }
        }
        else if (pA1 != null || pA2 != null)
        {
            if (pA1 != null)
            {
                pA1.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            }
            else if (pA2 != null)
            {
                pA2.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            }
        }
    }
예제 #7
0
파일: State.cs 프로젝트: kkiniaes/TBT
    public static State GetState(PhysicsModifyable pM)
    {
        State myState = new State ();
        myState.timeElapsed = Player.instance.TimeElapsed;
        myState.active = pM.gameObject.activeSelf;
        if (pM.gameObject.activeSelf) {
            myState.mass = pM.Mass;
            myState.charge = pM.Charge;
            myState.entangled = pM.Entangled;

            PhysicsAffected pA = pM.GetComponent<PhysicsAffected>();
            if (pA != null) {
                myState.velocity = pA.Velocity;
                myState.angularVelocity = pA.AngularVelocity;
                myState.position = pA.Position;
                myState.rotation = pA.Rotation;
            } else {
                myState.position = pM.Position;
                myState.rotation = pM.Rotation;
            }

            Goal g = pM.GetComponent<Goal>();
            if(g != null) {
                myState.combined = g.Combined;
                myState.numElementsCombined = g.numElementsCombined;
                myState.children = LevelManager.Clone(g.Children);
            }

            Switch[] switches = pM.GetComponents<Switch>();
            myState.activated = new bool[switches.Length];
            foreach (Switch s in switches) {
                myState.activated[s.SwitchIndex] = s.activated;
            }
        }

        return myState;
    }
예제 #8
0
파일: Goal.cs 프로젝트: kkiniaes/TBT
    // Update is called once per frame
    void Update()
    {
        //if(numElementsCombined > 1 && children.Count != 1) Debug.Log(children.Count);
        if (!combined)
        {
            if (Player.instance.timeScale > 0)
            {
                combineCooldown = Mathf.Max(0, combineCooldown - Time.deltaTime);
                foreach (Goal g in goals)
                {
                    if (combineCooldown <= 0 && Player.instance.timeScale > 0)
                    {
                        if (g != null && g.gameObject != null && g != this && !g.combined && touching(g))
                        {
                            float myCharge    = GetComponent <PhysicsModifyable>().charge;
                            float otherCharge = g.GetComponent <PhysicsModifyable>().charge;
                            if (g.numElementsCombined == numElementsCombined && (myCharge == 0 || otherCharge != myCharge))
                            {
                                Goal child  = null;
                                Goal parent = null;

                                if ((GetComponent <PhysicsAffected>() == null && g.GetComponent <PhysicsAffected>() != null) || g.id < id)
                                {
                                    child  = this;
                                    parent = g;
                                }
                                else
                                {
                                    child  = g;
                                    parent = this;
                                }

                                PhysicsAffected parentPA = parent.GetComponent <PhysicsAffected>();
                                PhysicsAffected childPA  = child.GetComponent <PhysicsAffected>();
                                if (parentPA != null && childPA != null)
                                {
                                    parentPA.Velocity = (parentPA.Velocity + childPA.Velocity) / 2f;
                                }
                                else if (parentPA != null)
                                {
                                    parentPA.Velocity /= 2f;
                                }

                                PhysicsModifyable parentPM = parent.GetComponent <PhysicsModifyable>();
                                PhysicsModifyable childPM  = child.GetComponent <PhysicsModifyable>();
                                if (parentPM.Entangled == null && childPM.Entangled != null)
                                {
                                    parentPM.Entangled = childPM.Entangled;
                                    if (parentPM.entangled != null)
                                    {
                                        parentPM.entangled.Entangled = parentPM;
                                    }
                                    childPM.Entangled = null;
                                }

                                parentPM.Mass   = 0;
                                childPM.Mass    = 0;
                                parentPM.Charge = 0;
                                childPM.Charge  = 0;

                                parent.children.Push(child);
                                parent.numElementsCombined++;
                                GameObject.Instantiate(combineEffect, parent.transform.position, Quaternion.identity);
                                child.Combine();
                            }
                        }
                    }
                }
            }
            else
            {
                combineCooldown = 0;
            }

            transform.localScale = hydrogenScale * Mathf.Sqrt(numElementsCombined);
            transform.GetChild(0).GetComponent <TextMesh>().text = System.Enum.GetNames(typeof(Element))[numElementsCombined - 1];
            if (GetComponent <PhysicsAffected>() != null)
            {
                GetComponent <PhysicsAffected>().Inertia = numElementsCombined / 2f;
            }

            if (!AntiMatterExplosion.exists && (int)LevelManager.instance.goalElement <= (numElementsCombined - 1))
            {
                Player.instance.LoadNextLevel();
            }
        }
    }
예제 #9
0
    public static void UnBind(PhysicsModifyable pM1, PhysicsModifyable pM2)
    {
        PhysicsAffected pA1 = pM1.GetComponent<PhysicsAffected>();
        PhysicsAffected pA2 = pM2.GetComponent<PhysicsAffected>();
        if(pA1 != null && pA2 != null) {
            if(pA1.GetComponent<FixedJoint>() != null) {
                Destroy(pA1.GetComponent<FixedJoint>());
            }

            if(pA2.GetComponent<FixedJoint>() != null) {
                Destroy(pA2.GetComponent<FixedJoint>());
            }
        } else if(pA1 != null || pA2 != null) {
            if(pA1 != null) {
                pA1.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
            } else if(pA2 != null) {
                pA2.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
            }
        }
    }
예제 #10
0
    public static void Bind(PhysicsModifyable pM1, PhysicsModifyable pM2)
    {
        PhysicsAffected pA1 = pM1.GetComponent<PhysicsAffected>();
        PhysicsAffected pA2 = pM2.GetComponent<PhysicsAffected>();
        if(pA1 != null && pA2 != null) {
            FixedJoint j1 = pA1.GetComponent<FixedJoint>();
            if(j1 == null || j1.connectedBody != pA2.GetComponent<Rigidbody>()) {
                if(j1 != null) {
                    Destroy(j1);
                }

                j1 = pA1.gameObject.AddComponent<FixedJoint>();
                j1.connectedBody = pA2.GetComponent<Rigidbody>();
            }

            FixedJoint j2 = pA2.GetComponent<FixedJoint>();
            if(j2 == null || j2.connectedBody != pA1.GetComponent<Rigidbody>()) {
                if(j2 != null) {
                    Destroy(j2);
                }

                j2 = pA2.gameObject.AddComponent<FixedJoint>();
                j2.connectedBody = pA1.GetComponent<Rigidbody>();
            }
        } else if(pA1 != null || pA2 != null) {
            if(pA1 != null) {
                pA1.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            } else if(pA2 != null) {
                pA2.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            }
        }
    }
예제 #11
0
    // Update is called once per frame
    void Update()
    {
        if (!LevelManager.instance.inBounds(Position))
        {
            if (GetComponent <PhysicsAffected>() == null)
            {
                Position = LevelManager.instance.reflect(Position);
            }
        }

        if (willBind && entangled != null)
        {
            Bind(this, entangled);
        }
        if (immutable)
        {
            specificallyImmutable.mass      = true;
            specificallyImmutable.charge    = true;
            specificallyImmutable.entangled = true;
        }

        Player player = Player.instance;

        Entangled = entangled;

//		GetComponent<Renderer>().material.SetFloat("_Power", 1f);

        if (chargeLockTimer > 0 && player.timeScale > 0)
        {
            chargeLockTimer -= Time.deltaTime * player.timeScale;
            charge           = 0;
        }

        if (mass == 0)
        {
            if (transform.FindChild("GravityWell(Clone)") != null)
            {
                transform.FindChild("GravityWell(Clone)").gameObject.SetActive(false);
            }
        }
        else
        {
            if (transform.FindChild("GravityWell(Clone)") != null)
            {
                transform.FindChild("GravityWell(Clone)").gameObject.SetActive(true);
            }
            else
            {
                GameObject temp = (GameObject)GameObject.Instantiate(gravityWell, transform.position, Quaternion.identity);
                temp.transform.parent = transform;
            }
            if (mass > 6)
            {
                mass = 6;
            }
            //following lines just handle the gravitywell particles
            transform.FindChild("GravityWell(Clone)").localRotation = Quaternion.identity;
            transform.FindChild("GravityWell(Clone)").GetComponent <ParticleSystem>().startSpeed    = -3 - mass;
            transform.FindChild("GravityWell(Clone)").GetComponent <ParticleSystem>().startLifetime = 1.5f - mass / 10f;
            transform.FindChild("GravityWell(Clone)").GetComponent <ParticleSystem>().emissionRate  = 300 + (mass / 2f);
            transform.FindChild("GravityWell(Clone)").localScale = (new Vector3(1 / transform.localScale.x, 1 / transform.localScale.y, 1 / transform.localScale.z)) * (1 + mass / 10f);
        }
//		else if(GetComponent<MeshRenderer>().enabled) {
//			if(transform.localScale.x < 0.1f || transform.localScale.y < 0.1f || transform.localScale.z < 0.1f) {
//				GetComponent<MeshRenderer>().enabled = false;
//				GameObject temp = (GameObject)GameObject.Instantiate(blackHole, transform.position, Quaternion.identity);
//				temp.transform.SetParent(transform, false);
//				temp.transform.localPosition = Vector3.zero;
//				transform.localScale = Vector3.one;
//				temp.transform.localScale = Vector3.one;
//				transform.FindChild("GravityWell(Clone)").gameObject.SetActive(false);
//			} else {
//				transform.localScale -= Vector3.one*Time.deltaTime;
//			}
//		}

        if (charge == 0)
        {
            if (transform.FindChild("NegativeCharge(Clone)") != null)
            {
                transform.FindChild("NegativeCharge(Clone)").gameObject.SetActive(false);
            }
            if (transform.FindChild("PositiveCharge(Clone)") != null)
            {
                transform.FindChild("PositiveCharge(Clone)").gameObject.SetActive(false);
            }
        }
        else if (charge != 0 && chargeLockTimer <= 0)
        {
            if (charge < 0)
            {
                if (transform.FindChild("PositiveCharge(Clone)") != null)
                {
                    transform.FindChild("PositiveCharge(Clone)").gameObject.SetActive(false);
                }
                if (transform.FindChild("NegativeCharge(Clone)") != null)
                {
                    transform.FindChild("NegativeCharge(Clone)").gameObject.SetActive(true);
                }
                else
                {
                    GameObject temp = (GameObject)GameObject.Instantiate(negativeCharge, transform.position, Quaternion.identity);
                    temp.transform.parent = transform;
                    Vector3 tempScale    = transform.FindChild("NegativeCharge(Clone)").localScale;
                    float   minDimension = Mathf.Min(Mathf.Min(tempScale.x, tempScale.y), tempScale.z);
                    transform.FindChild("NegativeCharge(Clone)").localScale = new Vector3(minDimension, minDimension, minDimension);
                }
                transform.Find("NegativeCharge(Clone)").GetComponent <ParticleSystemRenderer>().velocityScale = Mathf.Abs(charge);
            }
            else
            {
                if (transform.FindChild("NegativeCharge(Clone)") != null)
                {
                    transform.FindChild("NegativeCharge(Clone)").gameObject.SetActive(false);
                }
                if (transform.FindChild("PositiveCharge(Clone)") != null)
                {
                    transform.FindChild("PositiveCharge(Clone)").gameObject.SetActive(true);
                }
                else
                {
                    GameObject temp = (GameObject)GameObject.Instantiate(positiveCharge, transform.position, Quaternion.identity);
                    temp.transform.parent = transform;
                    Vector3 tempScale    = transform.FindChild("PositiveCharge(Clone)").localScale;
                    float   minDimension = Mathf.Min(Mathf.Min(tempScale.x, tempScale.y), tempScale.z);
                    transform.FindChild("PositiveCharge(Clone)").localScale = new Vector3(minDimension, minDimension, minDimension);
                }
                transform.Find("PositiveCharge(Clone)").GetComponent <ParticleSystemRenderer>().velocityScale = Mathf.Abs(charge);
            }

            if (player.timeScale > 0)
            {
                Collider[] cols = Physics.OverlapSphere(transform.position, NEUTRALIZE_DIST);
                List <PhysicsModifyable> toNeutralize = new List <PhysicsModifyable>();
                foreach (Collider col in cols)
                {
                    PhysicsModifyable colModifyable = col.GetComponent <PhysicsModifyable>();
                    if (colModifyable != null && Mathf.Sign(colModifyable.charge) != Mathf.Sign(charge) &&
                        colModifyable.charge != 0 && charge != 0)
                    {
                        toNeutralize.Add(colModifyable);
                        toNeutralize.Add(this);
                        GameObject temp = (GameObject)GameObject.Instantiate(lightning, (transform.position + col.transform.position) / 2, Quaternion.LookRotation(col.transform.position - transform.position));
                        temp.transform.localScale = Vector3.one * Vector3.Distance(transform.position, col.transform.position) / 30f;
                        SplitElementsBetween(transform.position, col.transform.position);
                    }
                }
                foreach (PhysicsModifyable modifyable in toNeutralize)
                {
                    modifyable.NeutralizeCharge();
                }
            }
        }

        if (entangled != null && !Player.instance.timeFrozen)
        {
            Transform fx = transform.FindChild("EntangledFX(Clone)");
            if (fx == null)
            {
                GameObject fxObject = Instantiate(entangledFX, transform.position, transform.rotation) as GameObject;
                fxObject.transform.parent = transform;
                fx = fxObject.transform;
            }
            for (int i = 0; i < 10; i++)
            {
//				Vector3 randVect = new Vector3(
//					(transform.position.x+entangled.transform.position.x)/2f,
//					(transform.position.y+entangled.transform.position.y)/2f,
//					(transform.position.z+entangled.transform.position.z)/2f);

                Vector3 randVect = Vector3.Lerp(transform.position, entangled.transform.position, Random.value);
                //Debug.Log(transform.position + " " + randVect + " " + entangled.transform.position);
                Vector3 inverseTransform = transform.InverseTransformPoint(randVect);
                inverseTransform.x *= transform.localScale.x;
                inverseTransform.y *= transform.localScale.y;
                inverseTransform.z *= transform.localScale.z;
                fx.GetComponent <ParticleSystem>().Emit(inverseTransform, new Vector3(Random.value - 0.5f, Random.value - 0.5f, Random.value - 0.5f), 0.5f, 0.5f, Color.white);
            }
        }

        if (player.timeReversed)
        {
            antiMatterAnnihilated = false;
        }
    }
예제 #12
0
    private void setPMToState(PhysicsModifyable pM, PhysicsAffected pA, State state)
    {
        pM.gameObject.SetActive(state.active);

        if (state.active)
        {
            pM.Entangled = state.entangled;
            pM.Mass      = state.mass;
            pM.Charge    = state.charge;

            if (pA != null)
            {
                pA.Velocity        = state.velocity;
                pA.AngularVelocity = state.angularVelocity;
            }

            pM.Position = state.position;
            pM.Rotation = state.rotation;

            Goal g = pM.GetComponent <Goal>();
            if (g != null)
            {
                if (state.combined)
                {
                    g.Combine();
                }
                else
                {
                    g.UnCombine();
                }

                g.numElementsCombined = state.numElementsCombined;
                if (!g.Children.Equals(state.children))
                {
                    Stack <Goal> newChildren = new Stack <Goal>();
                    while (state.children.Count > 0)
                    {
                        state.children.Peek().Combine();
                        newChildren.Push(state.children.Pop());
                    }
                    while (g.Children.Count > 0)
                    {
                        if (!newChildren.Contains(g.Children.Peek()))
                        {
                            g.Children.Peek().UnCombine();
                        }
                        g.Children.Pop();
                    }

                    g.Children = ReverseClone(newChildren);
                }
            }

            if (state.activated.Length > 0)
            {
                foreach (Switch s in pM.GetComponents <Switch>())
                {
                    s.activated = state.activated[s.SwitchIndex];
                    // s.transform.FindChild("SwitchParticles" + s.SwitchIndex).gameObject.SetActive(s.activated);
                }
            }
        }
    }
예제 #13
0
    // Update is called once per frame
    void Update()
    {
        if (timeElapsed <= 0 && timeResetting)
        {
            timeResetting = false;
            timeScale     = 1;
        }

        if (timeElapsed <= antimatterResetTime)
        {
            antimatterResetTime = -1;
        }

        GetMovementInput();
        GetTimeManipInput();
        GetVisualModeInput();

        if (!LevelManager.instance.inBounds(transform.position))
        {
            transform.position = LevelManager.instance.reflect(transform.position);
        }

        if (!loadNextLevel && GetComponent <Camera>().fieldOfView <= 90 && (Input.GetKeyDown(KeyCode.P) || Input.GetKeyDown(KeyCode.Escape)))
        {
            gamePaused = !gamePaused;
            pauseMenu.GetComponent <Animator>().SetBool("GamePaused", gamePaused);
            if (gamePaused)
            {
                pauseMenu.GetComponent <CanvasGroup>().interactable = true;
                pauseMenu.transform.FindChild("PauseTitle").GetComponent <LevelIntroText>().Start();
                timeReversed     = false;
                timeFrozen       = true;
                Cursor.visible   = true;
                Cursor.lockState = CursorLockMode.None;
            }
            else
            {
                pauseMenu.GetComponent <CanvasGroup>().interactable = false;
                timeReversed     = false;
                timeFrozen       = false;
                Cursor.visible   = false;
                Cursor.lockState = CursorLockMode.Locked;
            }
        }

        //time manipulation code
        if (timeFrozen)
        {
            if (timeScale < 0)
            {
                timeScale = Mathf.MoveTowards(timeScale, 0, Time.deltaTime * 3f * Mathf.Abs(REVERSE_TIME_SCALE));
            }
            else
            {
                timeScale = Mathf.MoveTowards(timeScale, 0, Time.deltaTime * 3f);
            }
            GetComponent <MotionBlur>().blurAmount = Mathf.MoveTowards(GetComponent <MotionBlur>().blurAmount, 0.5f, Time.deltaTime * 3f);
        }
        else
        {
            if (timeReversed)
            {
                entangleSelected = null;
                if (timeElapsed <= 0)
                {
                    timeReversed            = false;
                    timeResetting           = false;
                    timeElapsed             = 0;
                    noStateChangesThisFrame = true;
                }
                else
                {
                    timeScale = Mathf.MoveTowards(timeScale, REVERSE_TIME_SCALE, Time.deltaTime * 3f * Math.Abs(REVERSE_TIME_SCALE));
                    GetComponent <VignetteAndChromaticAberration>().chromaticAberration = Mathf.MoveTowards(GetComponent <VignetteAndChromaticAberration>().chromaticAberration, -timeScale * 30f, Time.deltaTime * 10f * Math.Abs(REVERSE_TIME_SCALE));
                }
            }
            else if (timeResetting)
            {
                timeScale = -100;
            }
            else
            {
                GetComponent <VignetteAndChromaticAberration>().chromaticAberration = Mathf.MoveTowards(GetComponent <VignetteAndChromaticAberration>().chromaticAberration, 0f, Time.deltaTime * 200f);
                if (timeScale < 0)
                {
                    timeScale = Mathf.MoveTowards(timeScale, 0, Time.deltaTime * 3f * Math.Abs(REVERSE_TIME_SCALE));
                }
                else
                {
                    timeScale = Mathf.MoveTowards(timeScale, 1, Time.deltaTime * 3f);
                }
            }

            if (!noStateChangesThisFrame || timeReversed || timeResetting)
            {
                timeElapsed             = Mathf.Max(0, timeElapsed + timeScale);
                noStateChangesThisFrame = true;
            }

            GetComponent <MotionBlur>().blurAmount = Mathf.MoveTowards(GetComponent <MotionBlur>().blurAmount, 0f, Time.deltaTime * 3f);
        }

        //First person controls
        float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
        float rotationY = transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * sensitivityY;

        if (Camera.main.fieldOfView <= 90f && !gamePaused)
        {
            transform.localEulerAngles = new Vector3(rotationY, rotationX, 0);
            transform.Translate(velocityVector * Time.deltaTime, Space.World);
            velocityVector = Vector3.MoveTowards(velocityVector, Vector3.zero, Time.deltaTime * 2f);
        }

        //switching skills
        if (!gamePaused)
        {
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                currentMode = PhysicsMode.Mass;
            }
            else if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                currentMode = PhysicsMode.Charge;
            }
            else if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                currentMode = PhysicsMode.Entangle;
            }
        }

        RaycastHit rh        = new RaycastHit();
        float      clipPlane = Camera.main.nearClipPlane;

        Camera.main.nearClipPlane = 0.1f;
        Ray cameraRay = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f));

        Camera.main.nearClipPlane = clipPlane;
        Debug.DrawRay(transform.position, cameraRay.direction * 10f);
        if (!gamePaused && Physics.Raycast(cameraRay.origin, cameraRay.direction, out rh, 100000, ~(1 << 10)))
        {
            GetComponent <DepthOfField>().focalLength = Vector3.Distance(transform.position, rh.point);
//			GetComponent<DepthOfField>().aperture = Mathf.MoveTowards(GetComponent<DepthOfField>().aperture, 10/(Vector3.Distance(transform.position, rh.point)), Time.deltaTime*10f);

            if (rh.transform.gameObject.GetComponent <PhysicsModifyable>() != null)
            {
                lookingAtObject = rh.transform.gameObject;

                if (!wireframeMode)
                {
                    lookingAtObject.GetComponent <AutoWireframeWorld>().HighlightObject();
                }

                PhysicsModifyable pM = rh.transform.gameObject.GetComponent <PhysicsModifyable>();
                rh.transform.gameObject.GetComponent <Renderer>().material.SetFloat("_Power", 0.3f);

                float delta = 10 * Input.mouseScrollDelta.y * Time.deltaTime;
                if (delta == 0)
                {
                    delta = (Input.GetKeyDown(KeyCode.UpArrow) ? 0.5f : 0) + -1 * (Input.GetKeyDown(KeyCode.DownArrow) ? 0.5f : 0);
                }

                if (!timeReversed && !timeResetting && !pM.immutable)
                {
                    //Increases/Decreases mass of object
                    if (!pM.specificallyImmutable.mass && currentMode == PhysicsMode.Mass)
                    {
                        float tempVal = pM.Mass;
                        pM.Mass = Mathf.Min(6, Mathf.Max(0, pM.Mass + delta));
                        if (pM.Mass != tempVal)
                        {
                            physicsSFXManager.GetComponent <PhysicsSFXManager>().PlayGravityChangeSFX(delta);
                        }
                    }                    // Increase/Decrease charge of object
                    else if (!pM.specificallyImmutable.charge && currentMode == PhysicsMode.Charge)
                    {
                        if ((pM.Charge == -1 && delta > 0) || (pM.Charge == 1 && delta < 0))
                        {
                            pM.Charge = 0;
                        }
                        else if (delta != 0)
                        {
                            pM.Charge = Mathf.Sign(delta);
                        }
                    }                    // Quantum Entangle objects
                    else                 // if(!pM.specificallyImmutable.entangled && currentMode == PhysicsMode.Entangle) {
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            if (pM.entangled != null)
                            {
                                //Debug.Log("Detangle");
                                pM.entangled.Entangled = null;
                                pM.Entangled           = null;
                                entangleSelected       = null;
                                if (entangleLine != null)
                                {
                                    Destroy(entangleLine.gameObject);
                                }
                            }
                            else if (entangleSelected != null && entangleSelected != pM)
                            {
                                //Debug.Log("Entangle " + pM + ":" + entangleSelected);
                                pM.Entangled = entangleSelected;
                                entangleSelected.Entangled = pM;
                                entangleSelected           = null;
                                if (entangleLine != null)
                                {
                                    Destroy(entangleLine.gameObject);
                                }
                            }
                            else if (!pM.specificallyImmutable.entangled)
                            {
                                //Debug.Log("Entangle " + pM);
                                entangleSelected = pM;
                                if (entangleLine == null)
                                {
                                    entangleLine = new GameObject("EntangleLine", typeof(LineRenderer));
                                    entangleLine.GetComponent <LineRenderer>().useWorldSpace  = true;
                                    entangleLine.GetComponent <LineRenderer>().sharedMaterial = Resources.Load <GameObject>("SwitchLine").GetComponent <LineRenderer>().sharedMaterial;
                                    entangleLine.GetComponent <LineRenderer>().material.color = Color.black;
                                    entangleLine.GetComponent <LineRenderer>().SetPosition(0, pM.transform.position);
                                }
                            }
                        }
                    }

                    if (currentMode == PhysicsMode.Mass || currentMode == PhysicsMode.Charge)
                    {
                        entangleSelected = null;
                    }
                }
            }
            else
            {
                lookingAtObject = null;
            }
        }
        else if (Input.GetMouseButtonDown(0))
        {
            // handles canceling entanglement
            entangleSelected = null;
            if (entangleLine != null)
            {
                Destroy(entangleLine.gameObject);
            }
        }
        else
        {
            lookingAtObject = null;
        }

        //Handles entangle indicator
        if (entangleLine != null)
        {
            LineRenderer entangleRenderer = entangleLine.GetComponent <LineRenderer>();
            if (entangleSelected != null)
            {
                entangleRenderer.SetWidth(Vector3.Distance(transform.position, entangleSelected.transform.position) / 30f, Vector3.Distance(transform.position, entangleSelected.transform.position) / 30f);
                if (lookingAtObject == null)
                {
                    entangleRenderer.SetPosition(1, transform.position + (transform.forward * Vector3.Distance(transform.position, entangleSelected.transform.position)));
                }
                else if (lookingAtObject != null && lookingAtObject.GetComponent <PhysicsModifyable>() != null)
                {
                    entangleRenderer.SetPosition(1, lookingAtObject.transform.position);
                }
            }
        }


        //Loading next level with cool transition
        if (loadNextLevel && !loadMainMenu)
        {
            loadNextLevelTimer += Time.deltaTime;
            if (loadNextLevelTimer > 2f)
            {
                if (loadingNextLevel == null)
                {
                    loadingNextLevel = Application.LoadLevelAsync(Application.loadedLevel + 1);
                    if (loadingNextLevel == null)
                    {
                        loadingNextLevel = Application.LoadLevelAsync(0);
                    }
                    loadingNextLevel.allowSceneActivation = false;
                    physicsSFXManager.GetComponent <PhysicsSFXManager>().PlayWarpingSFX();
                }
                starField.GetComponent <ParticleSystemRenderer>().lengthScale = Mathf.MoveTowards(starField.GetComponent <ParticleSystemRenderer>().lengthScale, 100, Time.deltaTime * 50f);
                Camera.main.fieldOfView = Mathf.MoveTowards(Camera.main.fieldOfView, 179f, Time.deltaTime * 30f);
                transform.Translate(transform.forward * Time.deltaTime * Camera.main.fieldOfView / 2f, Space.World);
                if (physicsSFXManager.GetComponent <AudioSource>().time / physicsSFXManager.GetComponent <AudioSource>().clip.length > 0.98f)
                {
                    loadingNextLevel.allowSceneActivation = true;
                }
            }
        }
        else if (!loadNextLevel && !loadMainMenu)
        {
            starField.GetComponent <ParticleSystemRenderer>().lengthScale = Mathf.MoveTowards(starField.GetComponent <ParticleSystemRenderer>().lengthScale, 1, Time.deltaTime * 50f);
            Camera.main.fieldOfView = Mathf.MoveTowards(Camera.main.fieldOfView, 90f, Time.deltaTime * Camera.main.fieldOfView / 3f);
            if (Camera.main.fieldOfView > 90f)
            {
                transform.Translate(transform.forward * Time.deltaTime * 10f, Space.World);
            }
        }
        else if (loadNextLevel && loadMainMenu)
        {
            lookingAtObject     = null;
            loadNextLevelTimer += Time.deltaTime;
            if (loadNextLevelTimer > 0.2f)
            {
                if (loadingNextLevel == null)
                {
                    StartCoroutine(LoadMainMenuSeamlessly());
                    loadingNextLevel.allowSceneActivation = false;
                    physicsSFXManager.GetComponent <PhysicsSFXManager>().PlayWarpingSFX();
                }
                starField.GetComponent <ParticleSystemRenderer>().lengthScale = Mathf.MoveTowards(starField.GetComponent <ParticleSystemRenderer>().lengthScale, 100, Time.deltaTime * 50f);
                starField.transform.localPosition = new Vector3(0f, 0f, -300f);
                Camera.main.fieldOfView           = Mathf.MoveTowards(Camera.main.fieldOfView, 179f, Time.deltaTime * 30f);
                transform.Translate(-transform.forward * Time.deltaTime * Camera.main.fieldOfView / 2f, Space.World);
                if (physicsSFXManager.GetComponent <AudioSource>().time / physicsSFXManager.GetComponent <AudioSource>().clip.length > 0.98f)
                {
                    Cursor.visible   = true;
                    Cursor.lockState = CursorLockMode.None;
                    loadingNextLevel.allowSceneActivation = true;
                }
            }
        }
    }
예제 #14
0
파일: Player.cs 프로젝트: kkiniaes/TBT
    // Update is called once per frame
    void Update()
    {
        if(timeElapsed <= 0 && timeResetting) {
            timeResetting = false;
            timeScale = 1;
        }

        if(timeElapsed <= antimatterResetTime) {
            antimatterResetTime = -1;
        }

        GetMovementInput();
        GetTimeManipInput();
        GetVisualModeInput();

        if(!LevelManager.instance.inBounds(transform.position)) {
            transform.position = LevelManager.instance.reflect(transform.position);
        }

        if(!loadNextLevel && GetComponent<Camera>().fieldOfView <= 90 && (Input.GetKeyDown(KeyCode.P) || Input.GetKeyDown(KeyCode.Escape))) {
            gamePaused = !gamePaused;
            pauseMenu.GetComponent<Animator>().SetBool("GamePaused",gamePaused);
            if(gamePaused) {
                pauseMenu.GetComponent<CanvasGroup>().interactable = true;
                pauseMenu.transform.FindChild("PauseTitle").GetComponent<LevelIntroText>().Start();
                timeReversed = false;
                timeFrozen = true;
                Cursor.visible = true;
                Cursor.lockState = CursorLockMode.None;
            } else {
                pauseMenu.GetComponent<CanvasGroup>().interactable = false;
                timeReversed = false;
                timeFrozen = false;
                Cursor.visible = false;
                Cursor.lockState = CursorLockMode.Locked;
            }
        }

        //time manipulation code
        if(timeFrozen) {
            if(timeScale < 0) {
                timeScale = Mathf.MoveTowards(timeScale, 0, Time.deltaTime*3f*Mathf.Abs(REVERSE_TIME_SCALE));
            } else {
                timeScale = Mathf.MoveTowards (timeScale, 0, Time.deltaTime * 3f);
            }
            GetComponent<MotionBlur>().blurAmount = Mathf.MoveTowards(GetComponent<MotionBlur>().blurAmount, 0.5f, Time.deltaTime*3f);
        } else {
            if(timeReversed) {
                entangleSelected = null;
                if(timeElapsed <= 0) {
                    timeReversed = false;
                    timeResetting = false;
                    timeElapsed = 0;
                    noStateChangesThisFrame = true;
                } else {
                    timeScale = Mathf.MoveTowards(timeScale, REVERSE_TIME_SCALE, Time.deltaTime*3f*Math.Abs(REVERSE_TIME_SCALE));
                    GetComponent<VignetteAndChromaticAberration>().chromaticAberration = Mathf.MoveTowards(GetComponent<VignetteAndChromaticAberration>().chromaticAberration, -timeScale*30f, Time.deltaTime*10f*Math.Abs(REVERSE_TIME_SCALE));
                }
            } else if(timeResetting) {
                timeScale = -100;
            } else {
                GetComponent<VignetteAndChromaticAberration>().chromaticAberration = Mathf.MoveTowards(GetComponent<VignetteAndChromaticAberration>().chromaticAberration, 0f, Time.deltaTime * 200f);
                if(timeScale < 0) {
                    timeScale = Mathf.MoveTowards(timeScale, 0, Time.deltaTime*3f*Math.Abs(REVERSE_TIME_SCALE));
                } else {
                    timeScale = Mathf.MoveTowards (timeScale, 1, Time.deltaTime * 3f);
                }
            }

            if(!noStateChangesThisFrame || timeReversed || timeResetting) {
                timeElapsed = Mathf.Max(0, timeElapsed + timeScale);
                noStateChangesThisFrame = true;
            }

            GetComponent<MotionBlur>().blurAmount = Mathf.MoveTowards(GetComponent<MotionBlur>().blurAmount, 0f, Time.deltaTime*3f);
        }

        //First person controls
        float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
        float rotationY = transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * sensitivityY;
        if(Camera.main.fieldOfView <= 90f && !gamePaused) {
            transform.localEulerAngles = new Vector3(rotationY, rotationX, 0);
            transform.Translate(velocityVector*Time.deltaTime, Space.World);
            velocityVector = Vector3.MoveTowards(velocityVector, Vector3.zero, Time.deltaTime*2f);
        }

        //switching skills
        if(!gamePaused) {
            if(Input.GetKeyDown(KeyCode.Alpha1)) {
                currentMode = PhysicsMode.Mass;
            } else if(Input.GetKeyDown(KeyCode.Alpha2)) {
                currentMode = PhysicsMode.Charge;
            } else if(Input.GetKeyDown(KeyCode.Alpha3)) {
                currentMode = PhysicsMode.Entangle;
            }
        }

        RaycastHit rh = new RaycastHit();
        float clipPlane = Camera.main.nearClipPlane;
        Camera.main.nearClipPlane = 0.1f;
        Ray cameraRay = Camera.main.ViewportPointToRay (new Vector3 (0.5f, 0.5f));
        Camera.main.nearClipPlane = clipPlane;
        Debug.DrawRay(transform.position, cameraRay.direction*10f);
        if(!gamePaused && Physics.Raycast(cameraRay.origin,cameraRay.direction, out rh, 100000, ~(1 << 10))) {
            GetComponent<DepthOfField>().focalLength = Vector3.Distance(transform.position, rh.point);
        //			GetComponent<DepthOfField>().aperture = Mathf.MoveTowards(GetComponent<DepthOfField>().aperture, 10/(Vector3.Distance(transform.position, rh.point)), Time.deltaTime*10f);

            if(rh.transform.gameObject.GetComponent<PhysicsModifyable>() != null) {
                lookingAtObject = rh.transform.gameObject;

                if(!wireframeMode) {
                    lookingAtObject.GetComponent<AutoWireframeWorld>().HighlightObject();
                }

                PhysicsModifyable pM = rh.transform.gameObject.GetComponent<PhysicsModifyable>();
                rh.transform.gameObject.GetComponent<Renderer>().material.SetFloat("_Power", 0.3f);

                float delta = 10 * Input.mouseScrollDelta.y*Time.deltaTime;
                if(delta == 0) {
                    delta = (Input.GetKeyDown(KeyCode.UpArrow) ? 0.5f : 0) + -1 * (Input.GetKeyDown(KeyCode.DownArrow) ? 0.5f : 0);
                }

                if(!timeReversed && !timeResetting && !pM.immutable) {
                    //Increases/Decreases mass of object
                    if(!pM.specificallyImmutable.mass && currentMode == PhysicsMode.Mass) {
                        float tempVal = pM.Mass;
                        pM.Mass = Mathf.Min(6, Mathf.Max(0, pM.Mass + delta));
                        if(pM.Mass != tempVal) {
                            physicsSFXManager.GetComponent<PhysicsSFXManager>().PlayGravityChangeSFX(delta);
                        }
                    }// Increase/Decrease charge of object
                    else if(!pM.specificallyImmutable.charge && currentMode == PhysicsMode.Charge) {
                        if((pM.Charge == -1 && delta > 0) || (pM.Charge == 1 && delta < 0)) {
                            pM.Charge = 0;
                        } else if(delta != 0) {
                            pM.Charge = Mathf.Sign(delta);
                        }
                    }// Quantum Entangle objects
                    else{// if(!pM.specificallyImmutable.entangled && currentMode == PhysicsMode.Entangle) {
                        if(Input.GetMouseButtonDown(0)) {
                            if(pM.entangled != null) {
                                //Debug.Log("Detangle");
                                pM.entangled.Entangled = null;
                                pM.Entangled = null;
                                entangleSelected = null;
                                if(entangleLine != null) {
                                    Destroy(entangleLine.gameObject);
                                }
                            } else if(entangleSelected != null && entangleSelected != pM) {
                                //Debug.Log("Entangle " + pM + ":" + entangleSelected);
                                pM.Entangled = entangleSelected;
                                entangleSelected.Entangled = pM;
                                entangleSelected = null;
                                if(entangleLine != null) {
                                    Destroy(entangleLine.gameObject);
                                }
                            } else if(!pM.specificallyImmutable.entangled){
                                //Debug.Log("Entangle " + pM);
                                entangleSelected = pM;
                                if(entangleLine == null) {
                                    entangleLine = new GameObject("EntangleLine", typeof(LineRenderer));
                                    entangleLine.GetComponent<LineRenderer>().useWorldSpace = true;
                                    entangleLine.GetComponent<LineRenderer>().sharedMaterial = Resources.Load<GameObject>("SwitchLine").GetComponent<LineRenderer>().sharedMaterial;
                                    entangleLine.GetComponent<LineRenderer>().material.color = Color.black;
                                    entangleLine.GetComponent<LineRenderer>().SetPosition(0,pM.transform.position);
                                }
                            }
                        }
                    }

                    if(currentMode == PhysicsMode.Mass || currentMode == PhysicsMode.Charge) {
                        entangleSelected = null;
                    }
                }
            } else {
                lookingAtObject = null;
            }
        } else if(Input.GetMouseButtonDown(0)) {
            // handles canceling entanglement
            entangleSelected = null;
            if(entangleLine != null) {
                Destroy(entangleLine.gameObject);
            }
        } else {
            lookingAtObject = null;
        }

        //Handles entangle indicator
        if(entangleLine != null) {
            LineRenderer entangleRenderer = entangleLine.GetComponent<LineRenderer>();
            if(entangleSelected != null) {
                entangleRenderer.SetWidth(Vector3.Distance(transform.position,entangleSelected.transform.position)/30f,Vector3.Distance(transform.position,entangleSelected.transform.position)/30f);
                if(lookingAtObject == null) {
                    entangleRenderer.SetPosition(1,transform.position + (transform.forward*Vector3.Distance(transform.position, entangleSelected.transform.position)));
                } else if(lookingAtObject != null && lookingAtObject.GetComponent<PhysicsModifyable>() != null) {
                    entangleRenderer.SetPosition(1,lookingAtObject.transform.position);
                }
            }
        }

        //Loading next level with cool transition
        if(loadNextLevel && !loadMainMenu) {
            loadNextLevelTimer += Time.deltaTime;
            if(loadNextLevelTimer > 2f) {
                if(loadingNextLevel == null) {
                    loadingNextLevel = Application.LoadLevelAsync(Application.loadedLevel + 1);
                    if(loadingNextLevel == null) {
                        loadingNextLevel = Application.LoadLevelAsync(0);
                    }
                    loadingNextLevel.allowSceneActivation = false;
                    physicsSFXManager.GetComponent<PhysicsSFXManager>().PlayWarpingSFX();
                }
                starField.GetComponent<ParticleSystemRenderer>().lengthScale = Mathf.MoveTowards(starField.GetComponent<ParticleSystemRenderer>().lengthScale, 100, Time.deltaTime*50f);
                Camera.main.fieldOfView = Mathf.MoveTowards(Camera.main.fieldOfView, 179f, Time.deltaTime*30f);
                transform.Translate(transform.forward*Time.deltaTime*Camera.main.fieldOfView/2f, Space.World);
                if(physicsSFXManager.GetComponent<AudioSource>().time/physicsSFXManager.GetComponent<AudioSource>().clip.length > 0.98f) {
                    loadingNextLevel.allowSceneActivation = true;
                }
            }
        } else if (!loadNextLevel && !loadMainMenu) {
            starField.GetComponent<ParticleSystemRenderer>().lengthScale = Mathf.MoveTowards(starField.GetComponent<ParticleSystemRenderer>().lengthScale, 1, Time.deltaTime*50f);
            Camera.main.fieldOfView = Mathf.MoveTowards(Camera.main.fieldOfView, 90f, Time.deltaTime*Camera.main.fieldOfView/3f);
            if(Camera.main.fieldOfView > 90f) {
                transform.Translate(transform.forward*Time.deltaTime*10f, Space.World);
            }
        } else if(loadNextLevel && loadMainMenu) {
            lookingAtObject = null;
            loadNextLevelTimer += Time.deltaTime;
            if(loadNextLevelTimer > 0.2f) {
                if(loadingNextLevel == null) {
                    StartCoroutine(LoadMainMenuSeamlessly());
                    loadingNextLevel.allowSceneActivation = false;
                    physicsSFXManager.GetComponent<PhysicsSFXManager>().PlayWarpingSFX();
                }
                starField.GetComponent<ParticleSystemRenderer>().lengthScale = Mathf.MoveTowards(starField.GetComponent<ParticleSystemRenderer>().lengthScale, 100, Time.deltaTime*50f);
                starField.transform.localPosition = new Vector3(0f, 0f, -300f);
                Camera.main.fieldOfView = Mathf.MoveTowards(Camera.main.fieldOfView, 179f, Time.deltaTime*30f);
                transform.Translate(-transform.forward*Time.deltaTime*Camera.main.fieldOfView/2f, Space.World);
                if(physicsSFXManager.GetComponent<AudioSource>().time/physicsSFXManager.GetComponent<AudioSource>().clip.length > 0.98f) {
                    Cursor.visible = true;
                    Cursor.lockState = CursorLockMode.None;
                    loadingNextLevel.allowSceneActivation = true;
                }
            }
        }
    }
예제 #15
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Rigidbody         myRB = GetComponent <Rigidbody>();
        PhysicsModifyable myPM = GetComponent <PhysicsModifyable>();

        if (!LevelManager.instance.inBounds(transform.position))
        {
            if (myPM.Entangled == null)
            {
                transform.position = LevelManager.instance.reflect(transform.position);
            }
            else
            {
                myPM.Entangled = null;
            }
        }

        if (Mathf.Abs(Player.instance.timeScale) == 1)
        {
            velocity        = myRB.velocity;
            angularVelocity = myRB.angularVelocity;
        }

        myRB.velocity        = velocity * Player.instance.timeScale;
        myRB.angularVelocity = angularVelocity * Player.instance.timeScale;

        foreach (PhysicsModifyable pM in objs)
        {
            if (pM != null && pM.gameObject != this.gameObject)
            {
                if (Player.instance.timeScale > 0)
                {
                    //Handles Gravity
                    if (pM.gameObject.activeSelf && pM.mass > 0 && pM.antiMatter)
                    {
                        float forceMagnitude = -Player.instance.timeScale * G * pM.mass * myRB.mass / Vector3.Distance(transform.position, pM.transform.position);
                        myRB.AddForce(Vector3.Normalize(pM.transform.position - transform.position) * forceMagnitude);

                        if (pM.GetComponent <PhysicsAffected>() != null)
                        {
                            pM.GetComponent <Rigidbody>().AddForce(Vector3.Normalize(transform.position - pM.transform.position) * forceMagnitude);
                        }
                    }
                    else if (pM.gameObject.activeSelf && pM.mass > 0)
                    {
                        float forceMagnitude = Player.instance.timeScale * G * pM.mass * myRB.mass / Vector3.Distance(transform.position, pM.transform.position);
                        myRB.AddForce(Vector3.Normalize(pM.transform.position - transform.position) * forceMagnitude);

                        if (pM.GetComponent <PhysicsAffected>() != null)
                        {
                            pM.GetComponent <Rigidbody>().AddForce(Vector3.Normalize(transform.position - pM.transform.position) * forceMagnitude);
                        }
                        //Handles Spaghettification around black holes (probably will end up removing)
//						if(pM.mass >= 6) {
//							transform.LookAt(pM.transform);
//							transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z + 1/Vector3.Distance(transform.position, pM.transform.position));
//						}
                    }
                }
            }
        }
    }
예제 #16
0
 // Use this for initialization
 new void Start()
 {
     base.Start();
     objectPhysics = attachedObject.GetComponent <PhysicsModifyable> ();
 }
예제 #17
0
 public static void TryAddPM(PhysicsModifyable pM)
 {
     if(!objs.Contains(pM)) {
         objs.Add(pM);
     }
 }