Creating a rolling ball character

nikki

28-10-2006 11:32:00

Hello everybody! I have a few problems implementing a player in my game. Here is an image with a description:-



In my game, the player is a rolling ball. The camera has a third-person view of the player. To turn the player, the user uses the mouse, making it rotate around the global Y axis. To move forward, the user has to press the W key, which applies a torque making it rotate around the local X axis. There shold be no rotation at all around the Z axis, even because of the action of gravity. So, he is just like a wheel, and the wheel should never slip or slide. I have been working on this for the past few hours, with varied results. This is what I have done so far:-

- I made the contact joint between the player and another body have an infinite amount of coulomb friction.

- I wrote some code that adds torque to the player when the W key is pressed. The torque vector is multipied by the player's orientation.

This is my problem:-
- When I make the player rotate around his Y axis by getting his orientation, multiplying it by a quaternion that rotates it around the Y axis, and setting the players orientation to the resulting quaternion, the player rotates around his local Y axis.

- I haven't tried this yet, but I think that if I put the player on a slope, there is a chance of rotation around the Z axis.

How can I solve these problems? Is there a better way to make the player accelerate?

Thanks for your help. :)

nikki

28-10-2006 12:32:33

Update:
I think I got almost everything, but I still can't stop him rotating around the local Z axis. For example, when he is going at high speed and turns suddenly, he starts rolling on his Z axis. That should not happen. He should only move in the direction of his local -Z or Z axis (no drifting or overturning). This is what I have until now (executed per frame):-
mBody->wake();

bool limit = mBody->getAngularVelocity().x < 200;

Vector3 torqueToAdd = Vector3(-850,0,0) * GlbVar.inMgr->getKeyboard()->isKeyDown(OIS::KC_W);
torqueToAdd += Vector3(850,0,0) * GlbVar.inMgr->getKeyboard()->isKeyDown(OIS::KC_S);
mBody->addRelativeTorque(torqueToAdd * limit);

Vector3 turn = mBody->getAngularVelocity();
Real yRot = GlbVar.inMgr->getMouse()->getMouseState().relX;
mBody->setAngularVelocity(Vector3(turn.x, yRot, turn.z));

I just checked out the Ode docs. It looks like Hinge 2 joint might help. Its called AngularMotorJoint in OgreOde right?

Any ideas how I can do it? :)

tuan kuranes

30-10-2006 08:55:03

Did you look at Ogre Wiki about OgreOde Walking character or ODE wiki about walking character ?
Perhaps you should ask on Ode mailing list about that...

nikki

30-10-2006 17:06:35

Yes, I checked the wiki. The article doesn't help much as it is not what I am trying to achieve, because I need the ball to continue rolling (momentum, inertia) when the acceleration key is released. I first used the yaw method mentioned in the article, which, unfortunately, yaws the player around his local Y axis, which, again, is not what I want. :(

Now I've fixed it completely, except one thing - how to stop an object from rotating around its Z axis. The player should never rotate around the Z axis.

Thanks for the help. :)

nikki

31-10-2006 09:04:15

Yay! I finally got it! :D

I stole a few ideas from the wiki 'walking character' entry. I used its method of creating a 'wheel-handlebar' joint to stop the player from rolling around his local Z axis. To turn, I turn the 'handlebar', and to accelerate, I add torque to the 'wheel'. The player is attached to the 'wheel'.

Thanks for the help! :)

tuan kuranes

31-10-2006 09:21:38

Thanks for the help!
:roll: Seems to me you made it alone !

btw, if you have some time, you are invited to add some info on the wiki, if someone mater want to reproduce your way of rolling ball character...

nikki

31-10-2006 16:54:34

I will, but maybe tomorrow. (got to sleep :) )