First-Person Shooter Discussion

Okay, we've discussed this several times and there are still some questions I have about this so I'm starting this topic to publically address each point and the best practice to accomplish it for writing the ground-work for a First-Person shooter style game.



The first question I would like answered is keeping my player from falling over in a physics world.  Now, of course, it would be more realistic if things could knock him over and he'd have to get back up, but for obvious reasons I (and most people I would assume) aren't really ready to travel down that road.  Now in my current game I have solved this problem zeroing out the values on update to keep them from ever rotating in a direction I don't want them to rotate in.  Is there a better way to do this in an environment where explosions are occurring and "physically" the player should fall, flip, or in any other way rotate off his feet?



darkfrog

Okay, after discussing this with Per it would seem as there's not much better way to do this other than zeroing out the values in the update() method.



Here is what I am currently doing in my game.  Per, correct me if this is not exactly what we discussed but this zeros out the x and z local rotation and the physics' angular velocity for x and z:



spatial.getLocalRotation().x = 0.0f;
spatial.getLocalRotation().z = 0.0f;
physics.getAngularVelocity().x = 0.0f;
physics.getAngularVelocity().z = 0.0f;



darkfrog

The next question is that of the physics object associated with your character.  Obviously you want your character to be a part of the physics world as well, and though you'll typically have a model associated with your character the default would be to have a box represent the physical bounds of your character, correct?



The problem with this is the friction created between that box and the ground (even a flat surface).  Perhaps I'm doing something wrong, but every time I've tried to do this I end up with either perpetual motion, or friction causing the box to bounce off the ground when I start to move too fast.  My temporary solution was to make my character at the top a box and a sphere attached at the moment so essentially he would roll instead of slide.  My initial thought is this is a bad solution.  What do you think?



darkfrog

darkfrog said:


physics.getAngularVelocity().x = 0.0f;
physics.getAngularVelocity().z = 0.0f;



This does not affect anything, as a new vector is created and returned by getAngularVelocity. You have to use setAngularVelocity instead.

As for the physical representation of the character: I like the jGorillaSumo… with slightly different parameters perhaps a good FPS char?

Irrisor,



How is that done exactly?  Does it use a box or some other method?



BTW, I had considered using a tall Sphere, but that currently doesn't work in jME-Physics.  Is that an issue on our side or with ODE?



darkfrog

darkfrog said:

How is that done exactly?  Does it use a box or some other method?

Moz uses joints to do this - see discussion here. But it is possible to do it simpler now: Create a sphere, attach it to a node, change the local translation to move the center of the sphere away from the center of the mass, then create a physics object from the node.


BTW, I had considered using a tall Sphere, but that currently doesn't work in jME-Physics.  Is that an issue on our side or with ODE?

ODE does not support ellipsoids as far as I know.

I need to look at the code for jGorillaSumo but my expectation is that it would just create a tall box.  How do I deal with the collision between that box and the ground to keep friction (avoid perpetual motion) and keep it on the ground?



darkfrog

Anyone have any specific ideas about how best to create a physics object for the main character?



(I could have just said "bump", but I figured this would be better)  :-p



darkfrog

. . . and then putting the center of mass very near to the floor, to have the 'capsule' stand up automatically . . .

Though IIRC setting the center of gravity has no effect (bug in ode/odejava), so you might have to go with a solution using joints anyway.

That's not true - test it yourself like I described above (the translation thing) - it works!

Ah, cool then! :slight_smile:



I was just remembering DP complaining about that when he was working on the car for his racing game.

Great, thanks for the assistance!  A little birdie told me that using an "inertia tensor" is a better way to go in order to keep the character from falling over.  Setting this to infinity or something?  I haven't had a chance to do any research into this but didn't know if you guys might know at all what I'm talking about. :o



darkfrog

How can the center of mass be changed?



Thanks.

Example from above:

irrisor said:
Create a sphere, attach it to a node, change the local translation to move the center of the sphere away from the center of the mass, then create a physics object from the node.

The center of mass is the point of reference of the spatial for which the DynamicPhysicsObject is created.
Create a sphere, attach it to a node, change the local translation to move the center of the sphere away from the center of the mass, then create a physics object from the node.


That works!

Thanks.

Anyone see my question about inertia tensor? :-p



darkfrog

How do you guys add a gun model in your FPS game?

Can you give a clue.

I got an M4A1 model, I wonder how to load it in the bottom of the screen in the FPS game.