Character controller problem, using IrrBullet

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
DawsonXB360
Posts: 13
Joined: Fri Mar 18, 2011 7:55 pm
Location: 219

Character controller problem, using IrrBullet

Post by DawsonXB360 »

Hi,

I'll get right into the problem. I'm using IrrBullet for my physics engine and I'm currently working on a character controller. The character controller is a box that has an affector, ICollisionObjectAffectorAttract, pulling it towards a point (the center of a globe I'm using as a map)

Code: Select all

ICollisionObjectAffector * affector = new ICollisionObjectAffectorAttract(Game::instance()->returnObjects()->returnWorld()->getPosition(), mass*1333);
This works fine, the problem arises in this code:

Code: Select all

	//	CONTROL MOVEMENT
	vector3df velocity(0,0,0); 
    vector3df localForward(0,0,0); 
    const matrix4& mat = Camera->getAbsoluteTransformation(); 
    f32 MoveSpeed = movement; 

	if(Game::instance()->returnReceiver()->IsKeyDown(KEY_KEY_W)) 
		localForward.Z = MoveSpeed; 

    if(Game::instance()->returnReceiver()->IsKeyDown(KEY_KEY_S)) 
		localForward.Z = -MoveSpeed; 

    if(Game::instance()->returnReceiver()->IsKeyDown(KEY_KEY_A)) 
		localForward.X = -MoveSpeed; 

    if(Game::instance()->returnReceiver()->IsKeyDown(KEY_KEY_D)) 
		localForward.X = MoveSpeed; 

    mat.rotateVect(velocity, localForward); 
		velocity.Y = 0.0f; 

   Body->setLinearVelocity(velocity*2000);
Because this is calling setLinearVelocity every step the affector is effectively ignored. What I'm looking for is a way to somehow add the velocity vector to the current velocity of the character without causing any problems.

I tried this code, it does account for the affector but just causes the velocity to exponentially increase every step:

Code: Select all

Body->setLinearVelocity(Body->getLinearVelocity+(velocity*2000));
I hope you guy understand this problem and can help me, it would be much appreciated :)
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Character controller problem, using IrrBullet

Post by serengeor »

DawsonXB360 wrote: I tried this code, it does account for the affector but just causes the velocity to exponentially increase every step:

Code: Select all

Body->setLinearVelocity(Body->getLinearVelocity+(velocity*2000));
Why wouldn't it?
It's like:

Code: Select all

int i=0;
while(...)
{
i=i+(i*2000);
}
If you want do increase the velocity but in some time, you should use force I think, And don't do the same with it as you did with velocity.
Working on game: Marrbles (Currently stopped).
DawsonXB360
Posts: 13
Joined: Fri Mar 18, 2011 7:55 pm
Location: 219

Post by DawsonXB360 »

Yes it is like the while loop but all that does is pretty much double the value of i every step. This is my problem, I need a way of adding the velocity vector that is obtained from camera rotation without it doubling every step.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

DawsonXB360 wrote:Yes it is like the while loop but all that does is pretty much double the value of i every step. This is my problem, I need a way of adding the velocity vector that is obtained from camera rotation without it doubling every step.
If you add, you will double. Using setLinearVelocity you specify the velocity you want it to go. If you want to increase the velocity either make another variable which gets increased/decreased, or use force/impulse/torque.
The first option is a bit overkill as you will have to use some timers to increase it at fixed time steps, or it will get really bad as framerate changes.

And irrBullet is not a physics engine.
Working on game: Marrbles (Currently stopped).
DawsonXB360
Posts: 13
Joined: Fri Mar 18, 2011 7:55 pm
Location: 219

Post by DawsonXB360 »

Thankyou. I'm messing around with applyForce and applyImpulse and I've got something that kind of works but is very sketchy. Can anyone give me any tips of how to set up a decent character controller?
DawsonXB360
Posts: 13
Joined: Fri Mar 18, 2011 7:55 pm
Location: 219

Post by DawsonXB360 »

Sorry about the double post but I really do need a tutorial on how to create a decent character controller in IrrBullet, or a bit of example code. It'll help other too. I'm rather stuck and I've searched all over the internet.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

DawsonXB360 wrote:Sorry about the double post but I really do need a tutorial on how to create a decent character controller in IrrBullet, or a bit of example code. It'll help other too. I'm rather stuck and I've searched all over the internet.
Thats a thing you have to think up on your own. There are many ways you can do it, so you need to think of what you expect from it.

For example I wrote my character controller that used bounding box, It was just a rigid body with a shape of box scaled up to models dimensions(also not falling over). And it worked for me the way I needed.

Think of what you expect from it and start writing it. You shouldn't expect from us writing your game for you. If you really can't deal with physics search for a team member that could work on physics for you, though this shouldn't be hard once you know what you'll need and you know what IrrBullet can provide you.
Working on game: Marrbles (Currently stopped).
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

DawsonXB360 wrote:Sorry about the double post but I really do need a tutorial on how to create a decent character controller in IrrBullet, or a bit of example code. It'll help other too. I'm rather stuck and I've searched all over the internet.
like sereongeor said, that is quite a task and there is no easy way one fix it all solution. everyones game is different and needs their own considerations for the character controller. take a look at my character controller wip on the 'everything 23-3d graphics board' if you want i can give you some pointers, but you cant expect us to just write your code for you.

the way i approach a design problem is like this:

WHAT do i want. you _always_ have to know exactly what it is you want.

what resources do i have availible

sketch *several* concepts out on paper or at least in your mind

prototype the promising concepts

once you have it narrowed down to maybe 2 begin final developement and integrate, reject, edit, revise and test test test test until you are happy with what you have.
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
Post Reply