IrrPhysx modifcation to support character controllers

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
ioannes
Posts: 5
Joined: Sun Feb 18, 2007 3:41 pm

IrrPhysx modifcation to support character controllers

Post by ioannes »

Hi Guys

While working on my own game engine using irrlicht and irrphysx I ran into the problem of irrphysx not supporting character controllers. After checking the forums I see JP said that he handen't got round to including them yet. Also he dosn't seem to have alot of time.

So I decided that I'd rather give extending irrphysx a go, than integrating Physx directly into my engine. Anyway I've managed to get it working and thought I'd release the source code to help anyone else who may want this functionality. the source can be found at http://www.2shared.com/file/6210772/9c9 ... cters.html

There is a readme file that gives a basic rundown on how to get the characters working. This is a source code only release so you will need to compile it yourself I use MSVC 2008 it should be fine with MS compilers but I think it may need some modification to compile under linux.

Below is a little screenshot of my game engine showing the capsules containing the characters of the game
Image

Feel free to modify it all you want especially if any elements of my coding style are not to your taste.

Hope someone finds this useful.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Sorry I have to do this... do you mind renaming the title to "IrrPhysx 4.0 (Now with character controllers!)" :oops: :lol:

Jk I love you jp :P
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
kingdutch
Posts: 76
Joined: Tue Sep 02, 2008 7:01 am

Post by kingdutch »

BlindSide wrote:Sorry I have to do this... do you mind renaming the title to "IrrPhysx 4.0 (Now with character controllers!)" :oops: :lol:
BlindSide, you are just cruel! :P

Anwho, nice addition to irrPhysX ioannes, not going to use it as I'm trying to implement PhysX directly but I'm in need of a character controller and I've learned a lot from irrPhysX so I'll definitely be taking a look at this too :D
if (msg.getRubbishFactor() > rubbishLimit) { ignorePost(); cout << how it should be done << "\n"; }
ioannes
Posts: 5
Joined: Sun Feb 18, 2007 3:41 pm

Post by ioannes »

Hi kingdutch if your working directly with the Physx Character SDK theres also a very good little tutorial hidden in the sdk it's in chapter12_other. I found it a great help when making my wrapper modification.

To be honest the character interface is actually quite simple I knocked my code up in about a night. Think the most annoying thing about it was when I realised you have to calculate the character displacement yourself and then get the character interface to check them. It's almost like the default irrlicht collision system except without the benifit of having gravity done for you lol.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Good work ioanne! Thanks!
yamashi
Posts: 82
Joined: Sat Jan 03, 2009 4:53 am

Post by yamashi »

Nice !
I got the character thingy working well not entirely.
My mesh moves according to the move function but it's not colliding with the map...
The camera is colliding with the map so I don't know if there is something special to do ?
Could you show an example code if possible ?

PS : The character doesn't fall either :/
PS2: camera + terrain scene node collision doesnt work either :/ it collides with completly random shapes and when i try to activate the debug data render it crashes...
Nothing works tbh

Thanks !
ioannes
Posts: 5
Joined: Sun Feb 18, 2007 3:41 pm

Post by ioannes »

Hi There

Yes some of your problems sound familiar to me. However it's hard for me to give you answers from such a vage description of how you've setup your scene.

So right now I'll post a code example of my character move function and give you a little description of how my scene is setup.

First up I'll address the move function and your characters lack of falling. The reason your character isn't being effected by gravity is that the physx character controller will not do that for you instead you must manually put gravity into your movement calculations. heres the code I use for my character.

Code: Select all

void CEntityCharacter::Move(vector3df dir, float fvel)
{
    m_graphics->getAbsoluteTransformation().rotateVect(dir);
    dir.normalize();
    dir *= fvel;
    SPhysxCharacterControllerFlags moveflags;
    //add on gravity to the dir
    dir.Y += GRAVITY;
    m_physics->move(dir,~0,moveflags);
    m_movedthisframe = true;
    if (moveflags.bottom)
    {
        m_onground = true;
    }
    else
    {
        m_onground = false;
    }
}
btw m_onground is a special bool value which lets me keep track of if the character is standing on sometihng or is in mid air. I call this function everytime I need to do an actual move or if the character is in mid air to apply gravity. The params dir and fvel are for the direction of the move and the distance to move by. Also note m_graphics is an Irrlicht scene node it's used to generate a normalised vector to pass to the m_physics (the character controller) move method.

That should now mean that your character will fall. As for the problems your having with your camera I'm unsure whats your using to control your camera, for instance is it also a irrphysx character controller or is it just a regular irrphyx physxobject? I've also had problems with terrain collisions and I've been having them with the regular irrphysx it's something to do with the way irrphyx works with terrain nodes. It seems if you scale them too much it will mess up.

Now heres a little description of what I have in the scene you can see from the screen shot. Firstly the character is standing on a large flat box that is a static irrphysx object (it has a mass of 0) . The other visble box is a regular irrphysx object and the character is being controlled by my irrphysx character controller. My camera is not controlled by irrphysx it's manually controlled by my mouse and keyboard.

Hope that helps.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Only just stumbled upon this! Nice work ioannes. I've not looked at the code myself but it's nice that you managed to make the extension and provided it for others to use.

I've got character controllers working well in IrrPhysx, it's been working for quite a few months now i should think i've just not had the time to finish it off and get it released. Fortunately I should have some more times on my hands very soon so I'll do my best to just get it all uploaded as it's gonna be really useful for a lot of people, including me and the game project I'm working on!
Image Image Image
baiqian
Posts: 43
Joined: Sun Apr 06, 2008 2:29 pm

Post by baiqian »

Ionnes, Could you show us a complete demo for the character control? Not sure how the physic object to associate with the character controller for the init.
JaskierPL
Posts: 10
Joined: Tue Apr 03, 2012 9:36 pm

Re: IrrPhysx modifcation to support character controllers

Post by JaskierPL »

Does anybody can upload this file again? Beacuse link is broken :(
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Re: IrrPhysx modifcation to support character controllers

Post by ACE247 »

I believe the code to the character control modification also resides somewhere in the later pages of the irrPhysX thread. You'd also have to extensively update this code to work with IrrLicht 1.7.x and the new PhysX API. ;)
wiedzmin112
Posts: 30
Joined: Tue Oct 18, 2011 3:48 pm

Re: IrrPhysx modifcation to support character controllers

Post by wiedzmin112 »

JP wrote:
In the IrrPhysx Game Example i did a very simple character controller made from a sphere which worked roughly ok so you might want to look at that. The next version of IrrPhysx will have character controllers in it (dread to think how long i've been saying that for...) but i'm not sure when that release will make it out... we've got some nasty bugs and little time to work on them
So you should check the game example
Post Reply