public bool AddRigidBody(BRigidBody rb)
 {
     if (!_isDisposed)
     {
         Debug.LogFormat("Adding rigidbody {0} to world", rb);
         if (rb._BuildRigidBody())
         {
             World.AddRigidBody(rb.GetRigidBody());
         }
         return(true);
     }
     return(false);
 }
Example #2
0
        void OnEnable()
        {
            objsIWasInContactWithLastFrame.Clear();
            BRigidBody brb = GetComponent <BRigidBody>();

            if (brb == null)
            {
                Debug.LogError("BCollisionCallback must be attached to a game object with a BRigidBody component.");
                return;
            }
            rigidBody = brb.GetRigidBody();
            world     = BPhysicsWorld.Get().World;
            if (contactCallback == null)
            {
                contactCallback = new ContactResultCallbackUnity(this);
            }
        }
Example #3
0
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if ((Time.time - lastShotTime) < (1 / maxShotsPerSecond))
                {
                    return;
                }

                Vector3    camPos = Camera.main.transform.position;
                Quaternion camRot = Camera.main.transform.rotation;

                GameObject go = BSphere.CreateNew(camPos + new Vector3(0, 0, 2), camRot);

                BSphere bs = go.GetComponent <BSphere>();
                bs.meshSettings = meshSettings;
                bs.BuildMesh();

                lastShotTime = Time.time;

                //linVel.Normalize();
                BRigidBody bRb = go.GetComponent <BRigidBody>();
                bRb.mass = mass;

                BulletSharp.RigidBody rb = bRb.GetRigidBody();

                rb.LinearVelocity             = (Camera.main.transform.forward * shootBoxInitialSpeed).ToBullet();
                rb.AngularVelocity            = BulletSharp.Math.Vector3.Zero;
                rb.ContactProcessingThreshold = 1e30f;

                go.GetComponent <MeshRenderer>().material.color =
                    new Color(UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f));

                Destroy(go, lifeTime);
            }
        }
 public bool AddRigidBody(BRigidBody rb)
 {
     if (!_isDisposed) {
         Debug.LogFormat("Adding rigidbody {0} to world", rb);
         if (rb._BuildRigidBody()) {
             World.AddRigidBody(rb.GetRigidBody());
         }
         return true;
     }
     return false;
 }