We are now going to use Farseer Physics Engine to add a gravitational force affecting the UFO. Also, we will add the possibility to apply a force to accelerate the UFO and to impulse it, updating its speed.
1. Stay in the
3DInvadersSilverlight
project.2. Open
InvadersGame.cs
.3. Add the following lines of code at the beginning (as we are going to use many Farseer's classes and interfaces):
using FarseerGames.FarseerPhysics; using FarseerGames.FarseerPhysics.Collisions; using FarseerGames.FarseerPhysics.Dynamics; using FarseerGames.FarseerPhysics.Factories; using FarseerGames.FarseerPhysics.Mathematics;
4. Add the following
private
variable in thepublic class InvadersGame : RealTimeGame
, to hold the newPhysicsSimulator
(FarseerGames.FarseerPhysics.PhysicsSimulator) instance:private PhysicsSimulator _physicsSimulator;
5. Add the following
private
method to initialize Farseer Physics Engine, specifying the desired gravitational...