示例#1
0
    void Solver(PhysicsRigidBody rigidBody, float deltaTime)
    {
        rigidBody.Velocity += (GRAVITY_FORCE * deltaTime);

        //check for collision
        SphereCollider sphereCollider = rigidBody.GetComponent <SphereCollider>();

        if (sphereCollider != null && PlaneCollider != null)
        {
            float vc = 1.0f;
            //check if on collision course with plane
            if (PlaneCollider.SphereCollisionOccured(sphereCollider, deltaTime, ref vc))
            {
                Vector3 newVelocity = rigidBody.Velocity.normalized * vc;
                rigidBody.Velocity = newVelocity;

                //todo project velocity along the plane
            }

            //check if sphere collides with other spheres
            foreach (var otherSphereCollider in SphereColliders)
            {
                if (sphereCollider.RigidBody == null || sphereCollider == otherSphereCollider)
                {
                    continue;
                }

                if (sphereCollider.SphereCollisionOccured(otherSphereCollider, deltaTime, ref vc))
                {
                    Vector3 newVelocity = rigidBody.Velocity.normalized * vc;
                    rigidBody.Velocity = newVelocity;
                }
            }
        }

        rigidBody.TranslatePosition(rigidBody.Velocity * deltaTime);
    }
示例#2
0
 void Awake()
 {
     RigidBody = GetComponent <PhysicsRigidBody>();
 }