Skip to main content
gamedev.net
🔒 Locked

Problems with player in ODE

Started by sirSolarius 0 replies 650+ views
Original Post
sirSolarius
sirSolarius
I implemented a player in ODE with this forum's help about a week ago. I made a capped cylinder, used an AMotor to prevent it from rotating, and added it to the scene. Now I have two problems: 1) I set a plane at y=0 for my initial testing purposes, but friction between the plane and my character is preventing most movement. When my character strafes or moves forward/backward, he should move without any y-component of movement, ie looking up at the sky or at the ground and hitting forward should produce the same behavior. Giving my player a force with a y-component of 0 stops almost all movement, however. Should I just disable friction for the player altogether? 2) How do I stop my character's movement? If I disable friction, the character just slides around after being given a force. I want the character to move as long as a button is held down, but once that button is released the character should stop. Right now I call a method on keydown that moves the character forward, and on keyup I apply the negative force. The problem is that I can't dynamically change direction (if I run straight and turn while holding forward down, I still go straight) and I still float around (precision errors maybe). Thanks for the help!
sbroumley
sbroumley
I haven't looked at the API for ODE, but setting the inverse inertia tensor matrix to all zeros will prevent an object from ever rotating (much simpler than using a motor I would have thought).

As for your questions:

1) It seems you should have at least a small value for friction just so the player comes to a stop on a slope etc.

2) Instead of a negative force, have you tried applying a force which is proportional to the current linear velocity (of course only do this when there are no direction keys pressed). Psuedo code something like:

// Assuming the ground plane has a normal of ( 0, 1, 0 )
VEC3 F = -Body.GetLinearVelocity() * k; // Bigger k = faster deceleration
F.Y = 0.0f;
Body.ApplyForce( F );

This will slow the body down horizontally, but allow movement (due to gravity) vertically.

You could also experiment with only applying the force parallel to the current arbitary ground plane (if the body is moving/resting on one). The code is only slightly more complex.
Steve Broumley

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.