O'Reilly logo

3D Game Development with Microsoft Silverlight 3 Beginner's Guide by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—detecting collisions between 3D characters

Your project manager does not want the UFOs to explode when they crash. He wants you to use the physics simulator to make them rotate and bounce when they collide.

Now, we are going to take advantage of the physics engine's collision detection capabilities:

  1. Stay in the 3DInvadersSilverlight project.
  2. Open Ufo.cs.
  3. Add the following public static constant to identify the kind of 3D character related to a geometry:
    public static string Tag = "UFO";
    
  4. Add the following private method to check the geometry that collides with the Ufo's instance:
    private bool OnCollision(Geom geom1, Geom geom2, ContactList contactList) { if ((((string) geom1.Tag) == Tag) && (((string) geom2.Tag) == Tag)) // Both geometries ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required