Marc's Character Controller

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Marc's Character Controller

Postby Marc » Sun Jul 08, 2012 12:07 pm

Hi! I'm also making a character controller. :)

I haven't made a dedicated test application for it, but you can try it out in the game I'm working on: http://www.transmogrifier.de/wo2/files/walkover2_setup.exe

Code: Select all
Controls
ESC    Return to Main Menu
WASD    walking
Space    jump
Shift   run
Tab    Switch between construction and weapons mode
F    turn on/off free flight
Q & Y    fly up/fly down in free flight and swim up/down while swimming
B   spawn heavy box

Construction Mode    
1    activate Pickaxe to remove Block
2    activate Sculpting Tool to raise and lower Corners
3-9, R & T    activate Materials to Place. r & t cycle through them. There are more materials then directly accessible through 3-9.

Weapon Mode    
1    activate Minigun
2    activate Shotgun
3    activate Rocketlauncher


It features (sry, I copied some formulations from physique):
+ Instant stair-stepping with no loss of speed.
+ Stand still on sloped ground, with a maximum slope angle.
+ jump
+ slide down illegal ramp
+ Push and be pushed by physics bodies.
+ Movement is fast and responsive!
+ character doesn't get airborne after running up a hill or while running down stairs

It can't crouch yet. I think it's easy portable to newton 3xx, but physique mentioned there is some issue with
the convex cast in newton 3xx right now and since this character controller relies on it, I haven't even tried.

It uses newton 2xx right now.

I release the source code as it is now. It's not a clean drop in for everybody since it needs to handle shapeids in the collision callback
and depending on how you handle those, you have to adjust code manually. I don't know if it's possible to make this easy usable without enforcing
something like this to the user. Also, there is the force and torque callback which basically just sets the force calculated before.
But since you might have a hierarchie of classes you point to with the userdata value of the bodies, I can't set it to the class of
the charactercontroller itself. It has to fit in your hierarchie. You can see it in my code where I cast it to a CUZUnit which is
the logical representation of a character in my code which in turn uses the character controller for movement.
Apart from that, it uses my own MVector class, but this could be substituted with another one.


Current Version:
https://dl.dropbox.com/u/103286/temp/MNewtonCharacterController20120721.7z

Old versions:
https://dl.dropbox.com/u/103286/temp/MNewtonCharacterController20120708.7z


You initialize it like this:

Code: Select all
   mncc = new MNewtonCharacterController();
   mncc->SetDefaultParameters();
   mncc->materialgroup = windowregionwalkover->ngroupunits;
   mncc->userdata = this;
   mncc->Init(windowregionwalkover->newtonworld, windowregionwalkover->newtonworld);


SetDefaultParameters() sets some default parameters which you can change. If you change them too much, some other magic numbers inside the code might have to
be changed as well - I'm not sure. But for everything between the size of 1 and 3 meters they should be ok.
The default character has a hight of 1.9m. You can see that from charr which is the height of the character cylinder + hover, which is the
distance the cylinder hovers above the ground.
Note that you can set two different newtonworld. One is the world the physics are calculated and a 2nd where the collisionshapes are created in.
If you only have one newtonworld you can set the same world twice. I generally have one world where I create the collisions so I don't have to
recreate them when I destroy my physics world and create a new physics world. Julio told me to do that some time ago.

At the end you destroy it with

Code: Select all
   mncc->Destroy();
   delete mncc;


In between, in your logic update step you do this before calling newtonupdate:

Code: Select all
   mncc->input_dir.Set(inputa.x, inputa.y, inputa.z);
   mncc->input_jump = input_jump;
   mncc->IteratePreNewtonUpdate();


inputa is a vector specifying the direction in which the character moves. depending on mncc->state you have to give slightly different values here.
for MNewtonCharacterControllerState_Floor, MNewtonCharacterControllerState_Fall, MNewtonCharacterControllerState_IllegalRamp you set
x,y to the direction in xy plane where the character should move to, z to 0. For the normal speed, the length should be 1.
However, you can adjust that and increase or decrease the length to make the character walk faster or slower.
For MNewtonCharacterControllerState_Fly, you have to additionally set the z value if the character should fly up or down. Note that flying is
equivalent to swimming from the perspective of this character controller. If you don't do either in your game, you can ignore this.
input_jump specifies if the character jumps right now.

After NewtonUpdate, you call
Code: Select all
   mncc->IteratePostNewtonUpdate()

Right now this only gets the position and velocity from the body and sets it accordingly to mncc->p and mncc->v so you can use it in your visualization and game logic.

I think there are some minor optimizations possible. For example: right now I use two cylinders. One for the feet and one for the upper part of the body.
I do it this way to differntiate if you collide with something small and push it or if I don't and can move over it so I can
hover over it in the next iteration and effectifly went up a stair. That's also why it needs a collisioncallback to differentiate
between these two cases. I'm not sure if this is the efficient way because it needs two cylinders and a compound. I could probably
replace it with only one cylinder and checking the height of the contacts in the collisioncallback.
Last edited by Marc on Sat Jul 21, 2012 6:13 am, edited 1 time in total.
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Marc's Character Controller

Postby belfegor » Sun Jul 08, 2012 3:24 pm

Thank you very much, i really appreciate your effort.
If you have more "goodies" to share please do, it can't never be enough demos/tutorials using Newton. :D

I tried your demo (game) a bit, and it feels good too me.
User avatar
belfegor
 
Posts: 53
Joined: Mon Sep 18, 2006 4:42 pm
Location: Serbia

Re: Marc's Character Controller

Postby pHySiQuE » Sun Jul 08, 2012 7:16 pm

Cool!
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Marc's Character Controller

Postby pHySiQuE » Sun Jul 08, 2012 7:16 pm

Cool, I'll try this out Monday!
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Marc's Character Controller

Postby FSA » Tue Jul 10, 2012 7:51 am

Cool. Can you make an option that the player dont push bodys and be pushed from bodys?
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Marc's Character Controller

Postby Marc » Tue Jul 10, 2012 2:06 pm

letter123 wrote:Cool. Can you make an option that the player dont push bodys and be pushed from bodys?

Hmm, that's a strange requirement. Usually, you probably want full interaction and might have to live with "have the player push other things but other things don't push the player". But anyways. There is no easy way to modify my code to do that. If you can live with an approximation, you can make the player really light in comparisson to the other bodies. But for absolutely no both way body interaction, you have to seperate the simulation of the bodies and simulate the player seperately and just add forces to the player while the other things just behave as if the player wasn't there. You can see something like that in Valve's free to play Team Fortress. The players are simulated independently and basically can move through each other without collision. On top of that they added "force fields" to them, just adding forces to players that are very close to each other. So you can walk into someone and when you stop walking, you get pushed out. But there is no hard cylinder cylinder collision.

It's really strange though. Are you really sure that's what you want? Maybe you could explain you scenario a bit more in detail? :o
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Marc's Character Controller

Postby FSA » Tue Jul 10, 2012 4:52 pm

I want that the player stop when walking into dynamic body. Like the Player in Amnesia and Penumbra. I'm searching a long time for a solution but havn't find it yet :( If you really can make this option i would be glad :) And in our game your name is in credits ;)
Greetings from Germany :P
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Marc's Character Controller

Postby Marc » Tue Jul 10, 2012 6:07 pm

letter123 wrote:I want that the player stop when walking into dynamic body. Like the Player in Amnesia and Penumbra. I'm searching a long time for a solution but havn't find it yet :( If you really can make this option i would be glad :) And in our game your name is in credits ;)
Greetings from Germany :P

Can you tell me which dynamic Object in Amnesia has this effect on the player? I remember that you can push everything around. No?
Apart from that, I also remember the developer of penumbra posting in here about how he made his character controller in penumbra. I don't remember the details, but here is the link: http://newtondynamics.com/forum/viewtopic.php?f=14&t=4508&hilit=character. The video linked there got removed, but I remember it to be a video of a capsule walking up and down stairs and then there was a video where it walked over a seesaw or something like that.
Also, I think if your target is to do an amnesia like game, you can probably do so with this character controller. If I'm wrong, can you tell me why?
Greeting from Germany as well :P
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Marc's Character Controller

Postby FSA » Tue Jul 10, 2012 6:38 pm

Every dynamic object don't move when player walk into it. Sorry but my knowledge of CharacterController is to small to write an own one :D And yes my target is a Amnesia like game. The whole physic system works great but the player controller don't work very good :)
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Marc's Character Controller

Postby Marc » Tue Jul 10, 2012 9:02 pm

letter123 wrote:Every dynamic object don't move when player walk into it. Sorry but my knowledge of CharacterController is to small to write an own one :D And yes my target is a Amnesia like game. The whole physic system works great but the player controller don't work very good :)

I'm still not sure that what you ask for is what you want and is what happens in Amnesia. If it were you could have a situation where the player stands somewhere and something drops from above on him. Because the falling thing doesn't get pushed by the player, it just falls through him and so things can travel through the player - which is really odd and I assume that's not what is happening in Amnesia.
Since you appear to want something my character controller cannot offer - it is based on newton's physics so there are always interactions in both directions - or maybe you still have to figure out what you really want, I suggest you open another thread to discuss it.
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Marc's Character Controller

Postby FSA » Wed Jul 11, 2012 7:40 am

I have played Amnesia now a second time. If the player walk to an dynamic object(door,chair,box) the player stops moving in this direction and the dynamic object don't get push away. But the player get pushed when something is falling at him.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Marc's Character Controller

Postby Marc » Wed Jul 11, 2012 8:57 am

letter123 wrote:I have played Amnesia now a second time. If the player walk to an dynamic object(door,chair,box) the player stops moving in this direction and the dynamic object don't get push away. But the player get pushed when something is falling at him.

Ok I tried it myself again. I think it's even more complicated. The door, you can move it with you mouse, but when it rests your character can't move the door. However, when I stand in front of the door and try to pull it open so that when I release the mouse button, the door still moves. Then, when it collides with the characters body, the door stops. It's not (noticably) pushing the character away. I haven't checked a situation where stuff hits me from above, but if it is like you say, then there are things that move a resting player around when they hit him, like the things that hit you from above, and there are things that just stop, like the door.
At first sight, I thought, you could just freeze all bodies that rest by adding a joint to them. But that's not what happens there I guess because you can throw a rock at the door and it moves. I'm not entirely sure if it's possible, but you could have a collisionscallback and depending on what collides, you could add the joint or remove it.
Why not make everything interakt with itself? You could make the door have a high friction and or mass so you can't move it around with your character easily.
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Marc's Character Controller

Postby FSA » Wed Jul 11, 2012 10:18 am

The Problem is that my boxes pushed away when I tried to jump on top of them. And when I walk at a wall with a dynamic object on front of "me" then the box starts to move crazy around and sticks in the wall after few moments.(With the newton character controller. I haven't try your one yet :) )
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Marc's Character Controller

Postby Marc » Fri Jul 13, 2012 4:11 am

That will work with my controller. However, there are two things to be considered:

- If you don't do anything special, there will be a limit in stacking things. If you build a high tower of boxes and jump on top you might shake around. There isn't much you can do about this in any physics engine beside manually helping by fixing bodies from game logic code. Just having one or two boxes on top of each other and jumping on them should not be a problem though.
- You have to think about, when something is the size of a stair-step lies in front of you and you walk towards it, do you want to move it away or do you want to step on it. You have to manually classify this for my controller by material-ids. A character controller can't know this by itself, you always have to tell it some way.

In the demo I posted before, you can try by hitting b a few times. That will spawn boxes. you can try jumping and walking around on them.
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: Marc's Character Controller

Postby Marc » Sat Jul 21, 2012 6:14 am

I fixed a bug letter123 told me about. I uploaded the fixed version and put the link in the initial post. The demo updates as well when you run update.exe.
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests