This is my Collision Detector:
[source lang="csharp"] public bool CheckForCollision(CustomModel c1, CustomModel c2) { for (int i = 0; i < c1.Model.Meshes.Count; i++) { // Check whether the bounding boxes of the two cubes intersect. BoundingSphere c1BoundingSphere = c1.Model.Meshes[i].BoundingSphere; c1BoundingSphere.Center += c1.Position; for (int j = 0; j < c2.Model.Meshes.Count; j++) { BoundingSphere c2BoundingSphere = c2.Model.Meshes[j].BoundingSphere; c2BoundingSphere.Center += c2.Position; if (c1BoundingSphere.Intersects(c2BoundingSphere)) { return true; } } } return false; }[/source]
This is my physics that I use to test it:
[source lang="csharp"] public void Update(GameTime gameTime, CustomModel model, float Mass, float Velocity) { if (collision.HasCollided == true) CollidedWithObject = true; ModelPositionHeight = model.Position.Y; if (CollidedWithObject == false) { ModelPositionHeight = (Velocity) - (0.5f * Mass * Time * (Time * Time)); model.Position = new Vector3(model.Position.X, ModelPositionHeight, model.Position.Z); Time += (float)gameTime.ElapsedGameTime.TotalSeconds; } if (CollidedWithObject == true) { model.Position = new Vector3(model.Position.X, ModelPositionHeight, model.Position.Z); } }[/source]
In my Main (game1) class:
[source lang="csharp"] customModel.Update(gameTime, models[0], 120, 250); collisionController.CheckForCollision(models[1], models[0]);[/source]
Edited by BluePhase, 22 October 2012 - 01:03 PM.






