Entity motion.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
incorrectbaboon
Posts: 3
Joined: Wed Jan 25, 2012 6:37 pm

Entity motion.

Post by incorrectbaboon »

Hi,

I'm working on the same project as al9191 (who has also been posting here recently). I am currently working on character motion, which needs to support forwards and backwards motion, rotating and strafing from side to side. So far, I have implemented rotation using a SingleEntityAngularMotor in servo mode, and Z-axis motion using a LinearAxisMotor in velocity mode. Each of these seems to work independently, however I'm having trouble using both at the same time. When I spawn my character, rotation seems to work fine, but as soon as I move away from the starting position, rotation starts misbehaving. As far as I can tell, the centre of rotation doesn't move with the character and instead stays where it is, the effect being that I start oscillating wildly (the 'wildness' is proportional to the distance from the starting position that I moved) as the servo tries to swing me into position about the centre. This oscillation spirals out of control and I end up being catapulted out of the map at a ridiculous speed.

This problem does not occur if I implement Z-axis motion by altering the Entity's velocities as opposed to using a LinearAxisMotor - everything works as I would expect (although I wanted to switch to using LinearAxisMotors because I'm having some slight accuracy trouble using the 'velocity method' which I don't get using the motor). I was wondering whether I'm using the classes incorrectly - am I supposed to be able to attach two motors to the same Entity? Does it sounds like I'm taking the right approach to implementing motion, and if so, is there anything obvious that I'm doing incorrectly?

Thanks a lot for any help :)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity motion.

Post by Norbo »

As far as I can tell, the centre of rotation doesn't move with the character and instead stays where it is
The SingleEntityAngularMotor does not keep track of a separate origin of rotation; it just directly operates on the orientation of the entity. It would not be responsible for wild swinging by itself. Something else may be interfering with it to produce the effect. For example, if another motor controlling position or linear velocity depended on and changed with the orientation, some weird feedback effects could show up. The LinearAxisMotor might be set up improperly for the desired effect.
am I supposed to be able to attach two motors to the same Entity?
So long as the motors are not configured in such a way that they fight each other, using multiple motors with one entity is perfectly acceptable.
Does it sounds like I'm taking the right approach to implementing motion, and if so, is there anything obvious that I'm doing incorrectly?
There is nothing obviously technically wrong in the description you have provided, so the problems are likely in a narrower scope of implementation.

Is this character a typical FPS style character (as opposed to the hovercrafty ghost-like thing al9191 posted about before)? If so, the CharacterController or SphereCharacterController would save a lot of time. They already handle all the little annoying bits robustly.
incorrectbaboon
Posts: 3
Joined: Wed Jan 25, 2012 6:37 pm

Re: Entity motion.

Post by incorrectbaboon »

Thanks a lot for the info :)

This is the same ghost-like vehicle that al9191 mentioned - he and I both are both working on the motion code. I have discovered that the adverse effects only begin occurring once I set the LinearAxisMotor's axis to a non-vertical vector, regardless of whether or not I ever actually move along that vector by setting a goal velocity at any point. Strangely, if I set the LAM's axis to be completely vertical, rotation on the spot using my SingleEntityAngularMotor causes me no trouble. However as soon as a horizontal element is introduced, the bugs resurface proportional to how non-vertical the axis is (again, this is before I have ever actually set a goal velocity on the LAM). If I never set the LAM's axis in the first place, rotation on the spot is fine (although of course I can't move). Can you think of any reason why this might be the case?

On a side note, what should the anchors of a world-relative LAM be? Am I right in assuming that they are the exact points on the connected entities that the runs between (for non-world-relative motors)? At the moment, I am not assigning anything to them, but don't really know if that's what I should be doing :P . The full set-up of my linear motor is as follows:

lamZ = new LinearAxisMotor();
lamZ.Settings.Mode = MotorMode.VelocityMotor;
lamZ.ConnectionA = gv.Body; // gv is the character, it's Body is a ConvexHull.
lamZ.ConnectionB = null;
lamZ.Axis = new Vector3(0f, 0f, 1f);
lamZ.IsActive = true;
Program.game.World.addToSpace(lamZ); // Adds the motor to our game world

On each movement, I intend to update lamZ.Axis = gv.Body.OrientationMatrix.Forward;

Is there anything dodgy-looking here? (Sorry for the incompetence - this is my first 3D/ large scale game programming experience!)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity motion.

Post by Norbo »

Is there anything dodgy-looking here?
The axis is parented to ConnectionA, so it's probably best to set ConnectionA to null and put the entity on ConnectionB. That way, the world axis won't change by itself because the 'world' doesn't rotate. Setting the Axis every frame would address the issue too by overriding the parenting effect.

When the axis is parented to the entity and the axis isn't reset every frame, odd unintuitive feedbacks can happen.
On a side note, what should the anchors of a world-relative LAM be? Am I right in assuming that they are the exact points on the connected entities that the runs between (for non-world-relative motors)? At the moment, I am not assigning anything to them, but don't really know if that's what I should be doing .
The anchor points are the points on the entities in world space which are 'attached' to the axis (using the word 'attached' loosely since it's a 1DOF constraint).

The Anchor properties are secondary to the LocalOffset properties. The default value of the zero vector works because it corresponds to the exact center of the entity. For a null 'world' connection, it doesn't really matter where it's connected, so it might as well be the zero vector too.
incorrectbaboon
Posts: 3
Joined: Wed Jan 25, 2012 6:37 pm

Re: Entity motion.

Post by incorrectbaboon »

It never occurred to me to switch the connections. Everything works perfectly now - I managed to sort everything out in a few minutes. Thanks a lot for all the help! :D
Post Reply