I'm attempting to make a player object that's controlled by a game pad. I'm using JiggleGame to test some things, and I'm stuck right off the bat. I'm trying to follow the DroneController from How do I add world force and the HoverController from Using rays to keep objects off the ground written by jwatte.
In the DroneController, there's this segment:
// resist any movement when dead owner_.Body.AddWorldTorque(owner_.Body.AngularVelocity * (-1 * owner_.Body.Mass));
I've created a simple controller, added that line, and it does nothing.
namespace JiggleGame { public class Player : PhysicObject { PlayerController controller; public Body Body { get { return body; } } public CollisionSkin CollisionSkin { get { return collision; } } public Player(Game game, Model model, float radius, float length, Vector3 position) : base(game, model) { Matrix orientation = Matrix.CreateRotationX(MathHelper.PiOver2); body = new Body(); collision = new CollisionSkin(body); collision.AddPrimitive( new Capsule(Vector3.Transform(new Vector3(-0.5f, 0, 0), orientation), orientation, radius, length), (int)MaterialTable.MaterialID.UserDefined, new MaterialProperties(0.8f, 0.7f, 0.6f)); body.CollisionSkin = this.collision; Vector3 com = SetMass(1.0f); body.MoveTo(position + com, Matrix.Identity); collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity)); body.EnableBody(); scale = new Vector3(radius, radius, length / 2); controller = new PlayerController(PlayerIndex.One, this); controller.Enabled = true; } public override void ApplyEffects(Microsoft.Xna.Framework.Graphics.BasicEffect effect) { effect.DiffuseColor = Color.Crimson.ToVector3(); } } public class PlayerController : JigLibX.Physics.Controller { private Player Owner; public PlayerController(PlayerIndex index, Player owner) { Owner = owner; } public override void UpdateController(float dt) { Owner.Body.AddWorldTorque(Owner.Body.AngularVelocity * -Owner.Body.Mass); } } }
In JiggleGame.cs, I added this to the end of LoadContent()
player = new Player(this, capsuleModel, 2.0f, 4.0f, new Vector3(8.0f, -5.0f, 5.0f)); Components.Add(player); CreateScene0();
The capsule is placed right in front of the car, so you just have to hit up to ram it. I've set up a break point in the controller, so I know that AddWorldTorque is being called when the controller is enabled, and not being called when disabled. This code doesn't seem to have any impact on the capsule at all. What am I doing wrong?