Beispiel #1
0
    protected override void realUpdate(GameObject obj)
    {
        Vector3 pos2 = obj.transform.position;
        Vector3 dir  = unityFire.getItemPos(thisObj) - pos2;
        double  r2   = dir.sqrMagnitude;
        phyObj  po   = obj.GetComponent <phyObj>();
        double  F    = (G * thisPo.getm() * po.getm()) / r2;

        dir.Normalize();
        unityFire.addItemForce(obj, (float)F, dir);
    }
Beispiel #2
0
    private void OnCollisionEnter(Collision collision)//只针对了对心碰撞?
    {
        GameObject gameobj1 = this.gameObject;
        phyObj     phyobj1  = GetComponent <phyObj>();
        GameObject gameobj2 = collision.gameObject;
        phyObj     phyobj2  = GetComponent <phyObj>();
        float      m1       = phyobj1.getm();
        Vector3    v1       = unityFire.getItemVelocity(gameobj1);
        float      m2       = phyobj2.getm();
        Vector3    v2       = unityFire.getItemVelocity(gameobj2);
        float      e        = phyobj1.gete() > phyobj2.gete() ? phyobj1.gete() : phyobj2.gete();
        Vector3    newv1    = (m1 * v1 + m2 * v2 - e * m2 * (v1 - v2)) / (m1 + m2);
        Vector3    newv2    = (m1 * v1 + m2 * v2 - e * m1 * (v2 - v1)) / (m1 + m2);

        unityFire.setItemVelocity(gameobj1, 1, newv1);
        unityFire.setItemVelocity(gameobj2, 1, newv2);
    }
    public override void update(GameObject obj)
    {
        phyObj po = obj.GetComponent <phyObj>();

        unityFire.addItemForce(obj, po.getm() * this.a, this.direction);
    }