/// <summary> /// Called when a preexisting collision continues. /// </summary> /// <param name="other"></param> /// <param name="manifoldList"></param> public override void BOnCollisionStay(CollisionObject other, PersistentManifoldList manifoldList) { for (int i = 0; i < callbacks.Count; i++) { callbacks[i].BOnCollisionStay(other, manifoldList); } }
/// <summary> /// Method is called whenever interactor collides with another object. /// Checks if the name of the other object contains the keyword of the gamepiece we are looking for and acts if so. /// </summary> /// <param name="other">The object the interactor collided with</param> /// <param name="manifoldList">List of collision manifolds--this isn't used</param> public override void BOnCollisionEnter(CollisionObject other, PersistentManifoldList manifoldList) { string gamepiece; for (int i = 0; i < collisionKeyword.Length; i++) { if (collisionKeyword[i] != null) { gamepiece = collisionKeyword[i]; if (other.UserObject.ToString().Contains(gamepiece)) { bool skip = false; //Debug.Log(other.UserObject.ToString()); GameObject tempGamepiece = ((BRigidBody)other.UserObject).gameObject; foreach (GameObject gp in heldGamepieces) { if (gp == tempGamepiece) { skip = true; } } if (!skip) { Debug.Log("does this happen"); collisionObject[i] = tempGamepiece; collisionDetected[i] = true; Debug.Log(collisionObject[i].ToString() + i.ToString()); } } } } }
public override void BOnCollisionEnter(CollisionObject other, PersistentManifoldList manifoldList) { if (other.UserObject.ToString() == "Player (BulletUnity.BCharacterController)") { kill = true; GameObject.FindGameObjectWithTag("Player").GetComponent <WeaponScript>().AddAmmo(); } }
public override void OnFinishedVisitingManifolds() { if (myCollisionObject == null) { return; } objectsToRemove.Clear(); foreach (CollisionObject co in otherObjs2ManifoldMap.Keys) { PersistentManifoldList pml = otherObjs2ManifoldMap[co]; if (pml.manifolds.Count > 0) { BOnCollisionStay(co, pml); } else { BOnCollisionExit(co); objectsToRemove.Add(co); } } for (int i = 0; i < objectsToRemove.Count; i++) { otherObjs2ManifoldMap.Remove(objectsToRemove[i]); } objectsToRemove.Clear(); for (int i = 0; i < newContacts.Count; i++) { PersistentManifoldList pml = newContacts[i]; CollisionObject other; if (pml.manifolds[0].Body0 == myCollisionObject) { other = pml.manifolds[0].Body1; } else { other = pml.manifolds[0].Body0; } otherObjs2ManifoldMap.Add(other, pml); BOnCollisionEnter(other, pml); } newContacts.Clear(); foreach (CollisionObject co in otherObjs2ManifoldMap.Keys) { PersistentManifoldList pml = otherObjs2ManifoldMap[co]; pml.manifolds.Clear(); } }
/// <summary> /// Method is called whenever interactor collides with another object. /// Checks if the name of the other object contains the keyword of the gamepiece we are looking for and destroys it if it does. /// </summary> /// <param name="other">The object the interactor collided with</param> /// <param name="manifoldList">List of collision manifolds--this isn't used</param> public override void BOnCollisionEnter(CollisionObject other, PersistentManifoldList manifoldList) { if (other.UserObject.ToString().Contains(gamepieceKeyword)) { GameObject gamepieceObject = ((BRigidBody)other.UserObject).gameObject; if (gamepieceObject.GetComponent <BFixedConstraint>() == null) { gamepieceObject.SetActive(false); // Destroying the gamepiece leads to issues if the gamepiece was the original. UpdateScore(); } } }
/// <summary> /// Method is called whenever interactor collides with another object. /// Checks if the name of the other object contains the keyword of the gamepiece we are looking for and destroys it if it does. /// </summary> /// <param name="other">The object the interactor collided with</param> /// <param name="manifoldList">List of collision manifolds--this isn't used</param> public override void BOnCollisionEnter(CollisionObject other, PersistentManifoldList manifoldList) { if (other.UserObject.ToString().Contains(gamepieceKeyword)) //.Contains() handles both gamepieces and their clones { GameObject gamepieceObject = ((BRigidBody)other.UserObject).gameObject; if (gamepieceObject.GetComponent <BFixedConstraintEx>() == null) //make sure gamepiece isn't held by robot { gamepieceObject.SetActive(false); // Destroying the gamepiece leads to issues if the gamepiece was the original. UpdateScore(); //change red or blue score } } }
public override void OnVisitPersistentManifold(PersistentManifold pm) { if (myCollisionObject == null) { return; } CollisionObject other; if (pm.NumContacts > 0) { if (pm.Body0 == myCollisionObject) { other = pm.Body1; } else { other = pm.Body0; } PersistentManifoldList pml; if (!otherObjs2ManifoldMap.TryGetValue(other, out pml)) { //todo get PersistentManifoldList from object pool //this is first contact with this other object //might have multiple new contacts with same object stored in separate persistent manifolds //don't add two different lists to new contacts bool foundExisting = false; for (int i = 0; i < newContacts.Count; i++) { if (newContacts[i].manifolds[0].Body0 == other || newContacts[i].manifolds[0].Body1 == other) { foundExisting = true; newContacts[i].manifolds.Add(pm); } } if (!foundExisting) { pml = new PersistentManifoldList(); newContacts.Add(pml); pml.manifolds.Add(pm); //don't add to otherObjs2ManifoldMap here. It messes up onStay do it after all pm's have been visited. } } else { pml.manifolds.Add(pm); } } }
/// <summary> /// This is called in bullet thread /// </summary> /// <param name="other"></param> /// <param name="manifoldList"></param> public override void BOnCollisionEnter(CollisionObject other, PersistentManifoldList manifoldList) { foreach (PersistentManifold manifold in manifoldList.manifolds) { for (int i = 0; i < manifold.NumContacts; i++) { ManifoldPoint manifoldPoint = manifold.GetContactPoint(i); lock (lck) { collisionPoint = manifoldPoint.PositionWorldOnB.ToUnity(); collistionNormal = manifoldPoint.NormalWorldOnB.ToUnity(); MustDisplay = true; CollisionEnter = true; } } } }
/// <summary> /// Method is called whenever interactor collides with another object. /// Checks if the name of the other object contains the keyword of the gamepiece we are looking for and destroys it if it does. /// </summary> /// <param name="other">The object the interactor collided with</param> /// <param name="manifoldList">List of collision manifolds--this isn't used</param> public override void BOnCollisionEnter(CollisionObject other, PersistentManifoldList manifoldList) { base.BOnCollisionEnter(other, manifoldList); if (other.UserObject.ToString().Contains(gamepieceKeyword)) //.Contains() handles both gamepieces and their clones { GameObject gamepieceObject = ((BRigidBody)other.UserObject).gameObject; if (gamepieceObject.GetComponent <BFixedConstraintEx>() == null) //make sure gamepiece isn't held by robot { if (!currentlyScoredObjects.Exists(i => i == gamepieceObject)) // Only score if it isn't currently score { gamepieceObject.SetActive(KeepScored); // Destroying the gamepiece leads to issues if the gamepiece was the original. currentlyScoredObjects.Add(gamepieceObject); // Track it UpdateScore(); //change red or blue score } } } }
public override void OnVisitPersistentManifold(PersistentManifold pm) { CollisionObject other; if (pm.Body0 == myCollisionObject) { other = pm.Body1; } else { other = pm.Body0; } PersistentManifoldList pml; if (!otherObjs2ManifoldMap.TryGetValue(other, out pml)) { //todo get from object pool pml = new PersistentManifoldList(); newContacts.Add(pml); } pml.manifolds.Add(pm); }
public virtual void BOnCollisionStay(CollisionObject other, PersistentManifoldList manifoldList) { }
public override void BOnCollisionStay(CollisionObject other, PersistentManifoldList manifoldList) { Debug.Log("On Collision Stay " + BPhysicsWorld.Get().frameCount); }
protected override void BOnCollisionStay(CollisionObject other, PersistentManifoldList manifoldList) { Debug.Log("On Collision Stay " + GetWorld().FrameCount); }
public override void BOnCollisionStay(CollisionObject other, PersistentManifoldList manifoldList) { Debug.Log("On Collision Stay"); }
public override void OnVisitPersistentManifold(PersistentManifold pm) { CollisionObject other; if (pm.Body0 == myCollisionObject) { other = pm.Body1; } else { other = pm.Body0; } PersistentManifoldList pml; if (!otherObjs2ManifoldMap.TryGetValue(other,out pml)) { //todo get from object pool pml = new PersistentManifoldList(); newContacts.Add(pml); } pml.manifolds.Add(pm); }
/// <summary> ///Beware of creating, destroying, adding or removing bullet objects inside these functions. Doing so can alter the list of collisions and ContactManifolds ///that are being iteratated over ///(comodification). This can result in infinite loops, null pointer exceptions, out of sequence Enter,Stay,Exit, etc... A good way to handle this sitution is ///to collect the information in these callbacks then override "OnFinishedVisitingManifolds" like: /// /// public override void OnFinishedVisitingManifolds() /// { /// base.OnFinishedVistingManifolds(); //don't omit this it does the callbacks /// do my Instantiation and deletion here. /// } /// </summary> protected virtual void BOnCollisionEnter(CollisionObject other, PersistentManifoldList manifoldList) { }