Ejemplo n.º 1
0
    public override void UpdateForce(ref PhysicsDataPtr pData, float dt)
    {
        if (id1 == null)
        {
            ForceManager.DeleteForceGenerator(this);
        }

        //TODO LINK UP TO ID THROUGH STATIC CLASS
        PhysicsDataPtr obj = id1.mpPhysicsData;

        float yPos   = obj.pos.y;
        float yForce = 0;

        if (yPos >= liquidPlaneY + maxDepth)
        {
            return;
        }
        else if (yPos <= liquidPlaneY - maxDepth)
        {
            yForce = objectVolume * liquidDensity;
        }
        else
        {
            yForce = liquidDensity * objectVolume * (yPos - maxDepth - liquidPlaneY) / (2 * maxDepth);
        }

        Vector2 force = new Vector2(0.0f, Mathf.Abs(yForce));

        obj.accumulatedForces += force;

        id1.mpPhysicsData = obj;
    }
Ejemplo n.º 2
0
    public override void UpdateForce(ref PhysicsDataPtr pData, float dt)
    {
        if (object1 == null || object2 == null)
        {
            ForceManager.DeleteForceGenerator(this);
        }


        Vector2 pos1 = object1.mpPhysicsData.pos;
        Vector2 pos2 = object2.mpPhysicsData.pos;

        Vector2 diff = pos1 - pos2;
        float   dist = diff.magnitude;

        float magnitude = restLength - dist;

        //if (magnitude < 0.0f)
        //magnitude = -magnitude;
        magnitude *= springConstant;

        diff.Normalize();
        diff *= magnitude;

        object1.mpPhysicsData.accumulatedForces += diff;
        object2.mpPhysicsData.accumulatedForces -= diff;
    }
Ejemplo n.º 3
0
    void CheckForTarget()
    {
        if (target == null)
        {
            Vector3 pos = new Vector3(Random.Range(xRange.x, xRange.y), Random.Range(yRange.x, yRange.y), 0);
            target = Instantiate(targetPrefab, pos, Quaternion.identity);

            ForceManager.DeleteForceGenerator(bfg);
            bfg = new BouyancyForceGenerator2D(target.GetComponent <Particle2D>(), 1.0f, 0.5f, 0, 1.5f);
            ForceManager.AddForceGenerator(bfg);
        }
    }
    // Update is called once per frame

    public override void UpdateForce(ref PhysicsDataPtr pData, float dt)
    {
        if (mPlanet == null)
        {
            ForceManager.DeleteForceGenerator(this);
            return;
        }

        Vector2 radiusVec = mPlanet.mpPhysicsData.pos - pData.pos;

        if (radiusVec.magnitude == 0)
        {
            return;
        }

        //radiusVec *= .5f;
        float gravitationalForce = (universalGavitationalConstant * (1 / mPlanet.mpPhysicsData.inverseMass) * (1 / pData.inverseMass)) / (radiusVec.magnitude * radiusVec.magnitude);

        radiusVec.Normalize();
        pData.accumulatedForces += gravitationalForce * radiusVec;
        //mPlanet.mpPhysicsData.accumulatedForces -= gravitationalForce * radiusVec;
    }