Ejemplo n.º 1
0
    void Start()
    {
        m_Instance = this;

        m_ForceObjects    = new List <ForceObject>();
        m_ForceObjectsHit = new List <ForceObject>();
        m_Blocks          = new List <Block>();

        for (int i = 0; i < 10; i++)
        {
            GameObject  forceObject       = Instantiate(Resources.Load <GameObject>("Prefabs/ForceObjectHit"));
            ForceObject forceObjectScript = forceObject.GetComponent <ForceObject>();
            forceObjectScript.Deactivate();
            m_ForceObjectsHit.Add(forceObjectScript);
        }

        for (int i = 0; i < 30; i++)
        {
            GameObject  forceObject       = Instantiate(Resources.Load <GameObject>("Prefabs/ForceObject"));
            ForceObject forceObjectScript = forceObject.GetComponent <ForceObject>();
            forceObjectScript.Deactivate();
            m_ForceObjects.Add(forceObjectScript);
        }

        for (int i = 0; i < 30; i++)
        {
            GameObject block       = Instantiate(Resources.Load <GameObject>("Prefabs/Block"));
            Block      blockScript = block.GetComponent <Block>();
            blockScript.Deactivate();
            m_Blocks.Add(blockScript);
        }

        m_LastUsedForceObject    = m_ForceObjects[0];
        m_LastUsedForceObjectHit = m_ForceObjectsHit[0];
    }
Ejemplo n.º 2
0
    public void Update()
    {
        time += Time.deltaTime;

        if (time >= targetTime)
        {
            time       = 0;
            targetTime = Random.Range(spawnRateMin, spawnRateMax);

            Vector2 spawn = new Vector2(
                Random.Range(boundTopLeft.x, bountBottomRight.x),
                Random.Range(boundTopLeft.y, bountBottomRight.y)
                );

            for (int i = 0; i < clusterSize; i++)
            {
                ForceObject inst = Instantiate(obj, transform);

                inst.transform.position = spawn;
                inst.Initalize(Random.Range(minMass, maxMass));

                spawn += new Vector2(Random.Range(0, clusterSpread), Random.Range(0, clusterSpread));
            }
        }
    }
Ejemplo n.º 3
0
 //THESE TWO FUNCTIONS WORK TO PREVENT MULTIPLE FORCE OBJECTS TRYING TO BE PARENTS AT ONCE BY HAVING SUCH BEHAVIOR LEAD TO ILLOGICAL PROGRAMMING
 public void SetParentForceObject(ForceObject obj)
 {
     if (parentForceObject != null)
     {
         throw new Exception("The Custom Force already has a parent object!");
     }
     parentForceObject = obj;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a custom force and applies it to the appliedTo force object.
 /// </summary>
 /// <param name="appliedTo"> the object the force is applied to. </param>
 /// <param name="forceApplierImplementation"> an interface through which logic for a particular custom force logic can communicate the force for the current frame. See implementations. </param>
 /// <param name="isPure"> if it is pure, then the force will not be affected by mass. </param>
 /// <param name="appliedFor"> the time for which the force is applied. if set to float.NegativeInfinity, then the force will be applied until outside code stops it. </param>
 public CustomForce(ForceObject appliedTo, ICustomForceImplementation forceApplierImplementation, bool isPure, float appliedFor, bool isLastForce = false)
 {
     IsPure     = isPure;
     AppliedFor = appliedFor;
     customForceImplementation = forceApplierImplementation;
     IsLastForce = isLastForce;
     appliedTo.ApplyNewForce(this);
 }
    //TODO this needs more and better work.

    //public void InitializeSerializedFields()
    //{

    //}

    public void InitializeNonSerializedFields(Func <bool> groundedCheck, ForceObject orientationHandled = null, MonoBehaviour unityEnumeratorObject = null)
    {
        canExertMotorForceCheck = groundedCheck;
        if (orientationHandled)
        {
            orientationHandled.onGravityAdjusted += OnMotorObjectGravityChanged;
            enumeratorObject = unityEnumeratorObject;
        }
    }
Ejemplo n.º 6
0
    public void OnTriggerExit2D(Collider2D collision)
    {
        ForceObject obj = collision.gameObject.GetComponent <ForceObject>();

        if (obj == null)
        {
            return;
        }
        objs.Remove(obj);
    }
    private void OnMotorObjectGravityChanged(ForceObject obj, Vector3 newGravity)
    {
        isOrienting = true;

        groundDir = newGravity.normalized;

        Quaternion lookQuaternion = Quaternion.LookRotation(motorMovementTransform.forward, -newGravity);

        enumeratorObject.StartCoroutine(ReOrientEnumeration(lookQuaternion));
    }
Ejemplo n.º 8
0
    //TODO will caching getter values change performance?

    public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo)
    {
        Vector3 projection = Vector3.Project(objectAppliedTo.GetRecentNetAcceleration(), NormalVector);

        if (projection.magnitude < (projection - NormalVector).magnitude)
        {
            return(Vector3.zero);
        }
        return(-projection * NormalForceMultiplier);
    }
Ejemplo n.º 9
0
    private void OnCollisionStay(Collision collision)
    {
        ForceObject forceObject = collision.collider.transform.GetComponent <ForceObject>();

        if (forceObject == null)
        {
            return;
        }

        CalculateApplySpeed(forceObject, collision.GetContact(0).normal);
    }
    private void GeneralCollisionEnter(ForceObject forceTarget, Vector3 contactFaceNormal)
    {
        Vector3 adjustment = (-Vector3.Project(forceTarget.GetRecentNetSpeed(), contactFaceNormal)) * normalForceInstantBounceMultiplier;

        forceTarget.DirectAdjustAddSpeed(adjustment);

        var normforce = new CustomOppositeAlongNormalForce(contactFaceNormal, normalForceStableMultiplier); //TODO this right now only supports one face. is only good for big platforms etc. anything further may need a deeper mesh-interacting physics though

        normforce.ApplyForce(forceTarget, true, float.NegativeInfinity);
        normalAppliedOn.Add(forceTarget, normforce);
    }
Ejemplo n.º 11
0
    private void OnTriggerEnter(Collider other)
    {
        ForceObject forceObject = other.GetComponent <ForceObject>();

        if (forceObject == null)
        {
            return;
        }

        forceObject.SetGravityBaseForce(newGravity);
    }
Ejemplo n.º 12
0
 public void RemoveParentForceObject(ForceObject obj)
 {
     if (parentForceObject == obj)
     {
         parentForceObject = null;
     }
     else
     {
         throw new Exception("The Custom Force object's parent was tried to be removed by reference from a different force object");
     }
 }
Ejemplo n.º 13
0
    public bool CeaseForceApplication()
    {
        if (currentParent == null)
        {
            return(false);
        }

        currentParent.RemoveForce(currentForceInstance);
        currentParent        = null;
        currentForceInstance = null;
        return(true);
    }
Ejemplo n.º 14
0
    public override void ApplyFrameForce(ForceObject mb)
    {
        if (mb.rb.mass > rb.mass * massCutoff)
        {
            return;
        }

        pull      = transform.position - mb.transform.position;
        pull_mag  = 1 * distanceFac / pull.magnitude;
        direction = pull.normalized;

        mb.rb.AddForce(direction * Time.fixedDeltaTime * forceFac * pull_mag);
    }
Ejemplo n.º 15
0
    private void CalculateApplySpeed(ForceObject forceObject, Vector3 normal)
    {
        if (Vector3.Angle(sourceMassObject.GetRecentNetSpeed(), normal) > 90)
        {
            return;
        }

        Vector3 projection = Vector3.Project(sourceMassObject.GetRecentNetSpeed() + sourceMassObject.GetRecentNetAcceleration(), normal); //TODO this bad. better if after physics

        Vector3 speedApplication = projection * massMultiplier / (isPure ? 1 : forceObject.GetMass()) * speedTransferranceMultipler;

        forceObject.DirectAdjustAddSpeed(speedApplication - lastSpeedApplied[forceObject]);

        lastSpeedApplied[forceObject] = speedApplication; //APPLY AFTER SYSTEM? If not work.
    }
Ejemplo n.º 16
0
    private void OnTriggerExit(Collider other)
    {
        if (!disableOnExit)
        {
            return;
        }

        ForceObject forceObject = other.GetComponent <ForceObject>();

        if (forceObject == null)
        {
            return;
        }

        forceObject.SetGravityBaseForce(GameProperties.Singleton.BaseGravity);
    }
Ejemplo n.º 17
0
    IEnumerator Asteroids()
    {
        while (true)
        {
            yield return(new WaitForSeconds(rate));

            if (!isSpawning)
            {
                continue;
            }
            Vector2 rand = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized *range;

            ForceObject obj = Instantiate(asteroidPre);
            obj.transform.position = transform.position + new Vector3(rand.x, rand.y, 0);
        }
    }
Ejemplo n.º 18
0
 public void ActivateForceObjectHit(Vector3 blockPosition)
 {
     for (int i = 0; i < m_ForceObjectsHit.Count; i++)
     {
         if (!m_ForceObjectsHit[i].gameObject.activeInHierarchy)
         {
             if (m_ForceObjectsHit[i].GetInstanceID() != m_LastUsedForceObjectHit.GetInstanceID())
             {
                 m_ForceObjectsHit[i].Deactivate();
                 m_ForceObjectsHit[i].Activate(blockPosition);
                 m_LastUsedForceObjectHit = m_ForceObjectsHit[i];
                 break;
             }
         }
     }
 }
Ejemplo n.º 19
0
    private void OnCollisionExit(Collision collision)
    {
        ForceObject forceObject = collision.collider.transform.GetComponent <ForceObject>();

        if (forceObject == null)
        {
            return;
        }


        allCollidingComponents[forceObject].Remove(collision.transform);
        if (allCollidingComponents[forceObject].Count < 1)
        {
            allCollidingComponents.Remove(forceObject);
            lastSpeedApplied.Remove(forceObject);
        }
    }
    public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo)
    {
        if (!canExertMotorForceCheck())
        {
            //NOT GROUNDED

            //do pure speed efforts

            //Vector3 currentSpeed

            return(Vector3.zero);
        }

        //GROUNDED

        if (pureSpeedDirty)
        {
            UndirtyPureSpeed();
        }

        Vector3 forwardForce  = motorMovementTransform.forward * forwardAccelerations[currentForwardIndex];
        Vector3 rightForce    = motorMovementTransform.right * backwardAccelerations[currentRightIndex];
        Vector3 leftForce     = -motorMovementTransform.right * rightAccelerations[currentLeftIndex];
        Vector3 backwardForce = -motorMovementTransform.forward * leftAccelerations[currentBackwardIndex];

        Vector3 adjustedWalkPlaneSpeed = Vector3.ProjectOnPlane(objectAppliedTo.GetRecentNetSpeed(), groundDir);

        Vector3 resultantForce = forwardForce + rightForce + leftForce + backwardForce;

        if (adjustedWalkPlaneSpeed.magnitude < NoMovementCutoff && resultantForce.magnitude < NoMovementCutoff)
        {
            objectAppliedTo.DirectAdjustAddSpeed(-adjustedWalkPlaneSpeed);
            return(Vector3.zero);
        }

        if (adjustedWalkPlaneSpeed.magnitude > maximumSpeedsPerIndex[currentMaxIndex])
        {
            resultantForce += -adjustedWalkPlaneSpeed.normalized * adjustmentAccelerations[currentMaxIndex];
        }

        //TODO doing it with just if might be faster becasue there is no addition with vector3.zero. Do diagnostic if releasing this code separately.

        return(resultantForce);
    }
Ejemplo n.º 21
0
    private void Start()
    {
        gravity = GameProperties.Singleton.BaseGravity;

        pCollider = GetComponent <Collider>();
        if (Singleton != null)
        {
            Destroy(gameObject);
            return;
        }

        Player = GameManager.Singleton.GetPlayerObject();

        Singleton = this;

        fo1 = Player.GetComponent <ForceObject>();

        //first boi enabled
    }
Ejemplo n.º 22
0
    private void OnCollisionEnter(Collision collision)
    {
        ForceObject forceObject = collision.collider.transform.GetComponent <ForceObject>();

        if (forceObject == null)
        {
            return;
        }


        if (!allCollidingComponents.ContainsKey(forceObject))
        {
            lastSpeedApplied.Add(forceObject, Vector3.zero);
            allCollidingComponents.Add(forceObject, new List <Transform>());
        }

        allCollidingComponents[forceObject].Add(collision.transform);

        CalculateApplySpeed(forceObject, collision.GetContact(0).normal);
    }
Ejemplo n.º 23
0
    public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo)
    {
        if (currentTime > switchingForces[currentIndex].time)
        {
            if (!repeatForever)
            {
                repetitionTimes--;
                if (repetitionTimes < 1)
                {
                    objectAppliedTo.QueueRemoveForce(parentForce);
                }
            }
            currentTime  = 0;
            currentIndex = (currentIndex + 1) % switchingForces.Length;
        }
        currentTime += Time.fixedDeltaTime;

        Vector3 force = switchingForces[currentIndex].forceVector;

        return(switchingForces[currentIndex].isLocal? (Vector3)(currentAppliedObject.transform.localToWorldMatrix * force) : force);
    }
Ejemplo n.º 24
0
 public abstract void ApplyFrameForce(ForceObject mb);
Ejemplo n.º 25
0
    //TODO will caching getter values change performance?

    public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo)
    {
        return((-objectAppliedTo.GetRecentNetSpeed().normalized *
                Mathf.Lerp(0, objectAppliedTo.GetObjectDragValue(), objectAppliedTo.GetRecentNetSpeed().magnitude / objectAppliedTo.GetAdjustedTrueMaximumSpeed())) * dragForceCoefficient);
    }
Ejemplo n.º 26
0
    public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo)
    {
        Vector3 between = objectAppliedTo.transform.position - distantTransform.transform.position;

        return((between.magnitude > minDistance) ? Vector3.zero : between.normalized *magnitude);
    }
Ejemplo n.º 27
0
    private void OnDeathCollision(Collider hit)
    {
        if (hit.tag == "Checkpoint")
        {
            if (checkpointCurrentCooldown > 0)
            {
                return;
            }

            checkpointCurrentCooldown = checkpointCooldown;


            ForceObject fo = GetComponent <ForceObject>();
            gravity = fo.GetGravityForce();

            if (checkpoint == hit.transform)
            {
                return;
            }

            if (checkpoint != null)
            {
                GameObject yes = Instantiate(GameProperties.Singleton.CheckPointDefaultGameobject);
                yes.transform.position   = checkpoint.transform.position;
                yes.transform.rotation   = checkpoint.transform.rotation;
                yes.transform.localScale = checkpoint.transform.localScale;

                Destroy(checkpoint.gameObject);
            }
            GameObject g = Instantiate(GameProperties.Singleton.CheckPointCheckedGameobject);
            checkpoint             = hit.transform;
            g.transform.position   = checkpoint.transform.position;
            g.transform.rotation   = checkpoint.transform.rotation;
            g.transform.localScale = checkpoint.transform.localScale;
            Destroy(hit.gameObject);
            checkpoint = g.transform;
        }

        if (hit.tag == "Death")
        {
            if (lives > 0)
            {
                Instantiate(ragdoll, Player.transform.position, Player.transform.rotation);
                Invoke("Checkpointer1", 0);
                lives -= 1;
            }

            if (lives == 0)
            {
                checkpoint = firstcheckpoint;
                fo1.DirectSetSpeed(stop);
                Player.transform.position = new Vector3(firstcheckpoint.position.x,
                                                        firstcheckpoint.position.y + heightrespawn, firstcheckpoint.position.z);
                Player.transform.position = new Vector3(firstcheckpoint.transform.position.x,
                                                        firstcheckpoint.transform.position.y + heightrespawn, firstcheckpoint.transform.position.z);
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
                lives = 10;
            }

            FindObjectOfType <AudioManager>().Play("PlayerDeath"); //Plays death sound after death
        }
    }
    public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo)
    {
        Vector3 dist = towardsTransform.transform.position - objectAppliedTo.transform.position;

        return((dist).normalized * (magnitude + distanceExtraCoeff * dist.magnitude));
    }
Ejemplo n.º 29
0
 public Vector3 GetCurrentForceVector(CustomForce parentForce, ForceObject objectAppliedTo)
 {
     return((Vector3.Project(constantForce, objectAppliedTo.GetRecentNetSpeed()).magnitude > upToSpeed)? Vector3.zero : constantForce);
 }
Ejemplo n.º 30
0
        /// <summary>
        /// ALEKSANDRA COPY AND PASTE DATAEXTRACTION.TESTING CODE HERE
        /// </summary>
        /// <returns></returns>
        public static ExportedResults PopulateDesignResults()
        {
            //Attach to existing SAP2000v22 model
            cHelper   myHelper    = new Helper();
            cOAPI     mySapObject = myHelper.GetObject("CSI.SAP2000.API.SapObject");
            cSapModel mySapModel  = mySapObject.SapModel;

            //Get list of all frames
            int numbernames = 0;

            string[] names = null;
            mySapModel.FrameObj.GetNameList(ref numbernames, ref names);

            string outputname = "";

            for (int i = 0; i < numbernames; i++)
            {
                bool notselected = false;
                mySapModel.FrameObj.GetSelected(names[i], ref notselected);

                if (notselected)
                {
                    outputname = names[i];
                    break;
                }
            }

            string point1 = "";
            string point2 = "";

            mySapModel.FrameObj.GetPoints(outputname, ref point1, ref point2);

            double x1 = 0;
            double y1 = 0;
            double z1 = 0;

            double x2 = 0;
            double y2 = 0;
            double z2 = 0;

            mySapModel.PointObj.GetCoordCartesian(point1, ref x1, ref y1, ref z1);
            mySapModel.PointObj.GetCoordCartesian(point2, ref x2, ref y2, ref z2);

            string pointname = point1;

            if (z2 < z1)
            {
                pointname = point2;
            }

            int numres = 0;

            string[] obj      = null;
            string[] elm      = null;
            string[] loadcase = null;
            string[] steptype = null;
            double[] stepnum  = null;
            double[] f1       = null;
            double[] f2       = null;
            double[] f3       = null;
            double[] m1       = null;
            double[] m2       = null;
            double[] m3       = null;

            mySapModel.Results.JointReact(pointname, eItemTypeElm.ObjectElm, ref numres, ref obj, ref elm, ref loadcase, ref steptype, ref stepnum, ref f1, ref f2, ref f3, ref m1, ref m2, ref m3);

            List <ForceObject> exportforce = new List <ForceObject>();

            for (int j = 0; j < numres; j++)
            {
                ForceObject fobj = new ForceObject(f1[j], f2[j], f3[j], m1[j], m2[j], m3[j]);
                exportforce.Add(fobj);
            }

            string propname = "";
            string sauto    = "";

            mySapModel.FrameObj.GetSection(outputname, ref propname, ref sauto);
            double fy         = 0;
            double fu         = 0;
            double efy        = 0;
            double efu        = 0;
            int    sstype     = 0;
            int    sshys      = 0;
            double strainhard = 0;
            double strainmax  = 0;
            double strainrupt = 0;
            string matprop    = "";

            mySapModel.PropFrame.GetMaterial(propname, ref matprop);
            mySapModel.PropMaterial.GetOSteel(matprop, ref fy, ref fu, ref efy, ref efu, ref sstype, ref sshys, ref strainhard, ref strainmax, ref strainrupt);
            Steel           steel  = new Steel(matprop, fy);
            Column          col    = new Column(propname, steel);
            ExportedResults expres = new ExportedResults();

            expres._column         = col;
            expres._name           = outputname;
            expres._exportedforces = exportforce;
            return(expres);
        }