1st Person

I have been making some good progress on developing a first-person shooter game using jME with the new physics engine but am having some issues with the camera.

I am trying to emulate that first-person perspective on the camera, but maintain the physics tie-in to the character to the world.  First what I did is create a box the height of a normal person, make it invisible, then turn it into a DynamicPhysicsObject.  That went pretty easily except it took me forever to figure out that setForceCull(true) makes the Object invisible and even further that it has to be done after it is added to the parent. Then every call to simpleUpdate I do a cam.setLocation(characterBox.getLocalTranslation()) and I'm looking out of my box.

Now what I am trying to figure out is how to force the box to always remain vertical but maintain all other physics dimensions?  It would be pretty lame for my character to be falling over all the time…wouldn't you agree? :)  Besides correcting any "balance issues" on my box everytime simpleUpdate() is called is there any better way to lock a physics dimension?  If not this would be a very beneficial feature to have.

BTW, I've been posting a lot on here recently because I just recently picked this up and I'm determined to write my first game by the end of the month.

Thank you,

darkfrog

i dont know if i am right here but i think so so i will try

it seems like u'r using an extension of Simple Game which has some set Made in the init

One of theese is the FrustumView

/** Set up how our camera sees. */

cam.setFrustumPerspective(45.0f,

(float) display.getWidth() /

(float) display.getHeight(), 1, 1000);

Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);

Vector3f left = new Vector3f( -1.0f, 0.0f, 0.0f);

Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);

Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);

i think making one that fits your own would solve the problems

I don't really know how that would help my situation?  I am trying to apply physics here properly to the character…I'm not having any problem getting the camera to follow the object…on the contrary, I create an explosion beside him and it gets a little scary.

The problem I'm having is making the "body" of my character (which is a tall box) stay vertical and not fall over when a force is applied to it that would cause a normal box to flip over…obviously that would be bad for the character to flip and land on his head…not going for quite that much realism yet.

Thanks,

darkfrog

You do this most easily by:

1. invisibleBox.getLocalRotation().set(0,0,0,0); // Reset the rotation of the spatial bound to the body.
2. playerPhysics.syncToGraphical(); // Sync rotation and translation to the spatial.

Hope that helps!

Awesome!  I look forward to giving this a try tonight!

Thanks,

darkfrog

Great, that works, thanks!

I keep on having a strange issue coming up and I'm not sure if anyone else is experiencing it.  I haven't taken the time to debug and figure out what circumstances causes this, but I keep getting this message:

ODE Message 2: vector has zero size (ode/src/odemath.cpp:128)

When it starts happening it just outputs that over and over until I close the VM.

Thanks,

darkfrog

Hmm, not sure what that means… are you using the latest* odejava native provided by us?

• the one in the CVS libs folder.

Yes, I believe so but I'll verify tonight and get back to you.  It's possible I'm using the one they provide instead.

It seems that everything continues to work as I would expect, it's just continuously throwing that error until I shut down.

Thanks,

darkfrog

Yes, I had that problem, too. You seem to use our native, as the standard ode native crashes after printing this error

I did not take much time to find the reason either (just fixed the crash). But some ode-data seems to be messed up when it's printed.

If you have the time to dwell on that, it would be great.

I believe the problem is being caused by me passing negative numbers to a spatial and then calling syncWithGraphical() on the physics object.

I am having some issues with trying to make my spatial's rotation sync with the camera's rotation, is there an easy way to do this? (this is for first-person perspective utilizing a physics object in order to maintain collisions)

Also, I am using addForce() to move the "character" around on the map.  The friction between the box (that's what the character currently is) and the ground makes the box jump (I've locked the rotation so it can't flip over or anything) but I think if I could just make my character "slick" as ice this would be perfect.  How do I change the physics object so that friction isn't created when moving around but I don't slide all over the place?

Thanks,

darkfrog

Okay, after even further diagnosing I have been able to reproduce the problem consistently when using the DLL provided with jME-Physics.  However, if I switch to the DLL provided directly by ODE it works just fine.

The following code in the Game update method seems to be consistently reproducing it:

spatial.getLocalRotation().set(0.0f, spatial.getLocalRotation().y, 0.0f, 0.0f);

physicsObject.syncWithGraphical();

BTW, still hopeful on a response for the friction and camera rotation questions.

Thanks,

darkfrog

darkfrog said:

Okay, after even further diagnosing I have been able to reproduce the problem consistently when using the DLL provided with jME-Physics.  However, if I switch to the DLL provided directly by ODE it works just fine.

Uhu, which is quite strange. Where did you get/build the dll from? Probably sanity checks are switched off?

The following code in the Game update method seems to be consistently reproducing it:

spatial.getLocalRotation().set(0.0f, spatial.getLocalRotation().y, 0.0f, 0.0f);
physicsObject.syncWithGraphical();
Ah, interesting, but this is not a valid rotation - so the fact that ODE is complaining is ok. The question why an invalid rotation is caused remains...

BTW, still hopeful on a response for the friction and camera rotation questions.

Concerning the friction: you specify this in the physics call back - give it a shot. (e.g. have a look into BuggeDemo)
I thought the camera stuff was not a problem? What do you want to know?

I appreciate your prompt response.  As for the ODE dll I updated from jME-Physics CVS repository last night and tried with that one with those results.

As for my code block there, I ahve been trying to develop a method of having my "first person" be bound by physics but not be able to fall over.  I created a Box for the the character, made it invisible, and run that with every update so that it never flips.  I am trying to also make it so that moving the mouse rotates the character as well.

Perhaps I'm going about this the wrong way.  If so, please tell me a better way. :)  Essentially I am just trying to write a FPS where I am looking through the eyes of my character and that character is bound in the physics world.  The reason for this is so collisions will be the same and I can addForce when I want my character to move a direction.  That way I don't have to be concerned about anything but the actual direction they want to go and force that they are exerting to get there.  The physics world takes care of what happens to them.

I will take a look at that demo though.  Please explain why that is not a valid rotation?  If you can't think of a better way then I just need to know how to sync the camera's rotation to the character/spatial's rotation.

Thanks,

darkfrog

Great!  I figured out the PhysicsCallBack and after setMu(1.0f) and setSlip2(1.0f) and setBounce(0.0f) I think I've got the effect I'm looking for.

As for the first person effects I changed my update method to use this instead:

Spatial spatial = world.getFirstPerson().getSpatial();

spatial.getLocalRotation().x = 0.0f;

spatial.getLocalRotation().z = 0.0f;

world.getFirstPerson().getPhysicsObject().syncWithGraphical();

World is my own custom class, but this allows me to rotate my character without worrying about getting flipped over.

As for character controls I've done the following and I'm not sure if this is the best way to go, I'm looking for some constructive criticism if there's a better way:

DynamicPhysicsObject physics = (DynamicPhysicsObject)element.getPhysicsObject();

if (type == FORWARD) {

} else if (type == BACKWARD) {

} else if (type == STRAFE_LEFT) {

} else if (type == STRAFE_RIGHT) {

} else if (type == ROTATE_LEFT) {

} else if (type == ROTATE_RIGHT) {

} else if (type == JUMP) {

}

Thanks,

darkfrog

Outside of syncing the camera to my character for rotation I think I'm nearly done with this aspect of the project.  I've come up with a few helper classes that I'll post if anyone is interested in them to help creating a FPS style game.

Thanks,

darkfrog

darkfrog said:
As for the ODE dll I updated from jME-Physics CVS repository last night and tried with that one with those results.
I meant the "DLL provided directly by ODE"

Please explain why that is not a valid rotation?
w should not be zero, I wonder why this works for your cam - should cause some glitches, doesn't it?

If you can't think of a better way then I just need to know how to sync the camera's rotation to the character/spatial's rotation.

Did not quite get the prob here  :?
What about creating CameraNode and put it inside your player node? You have done this, haven't you?

No, I haven't done that…how do I do that? :o

I was looking at my Spatial and can't figure out how how to add the camera to it?

Thanks,

darkfrog

You can create a CameraNode and attach this to a Node. If your player is just a box atm create a Node and add the box into that new Node. Then use the Node as player spatial instead of the box (when creating physics and stuff). The camera is automatically updated then.

So like…

Node character = new Node("Character");

character.attachChild(characterSpatial);

CameraNode cameraNode = new CameraNode("CameraNode", camera);

character.attachChild(cameraNode);

I tried this code and the camera didn't attach…

Is there something else I have to do?

Thanks,

darkfrog

Oops, disregard that last message, I figured it out…I forgot to add my Node to the rootNode.

Okay, it all seems to work except the controls are kind of hoaky for Forward, Backward, Left Strafe, Right Strafe, Rotate Left, Rotate Right, and Jump.  I think I can get jump to work with some tweeking and forward and backward seem to work okay like they are, but I don't suppose there's any example code out there for a first-person shooter style game using jME Physics?  I am primarily having problems with the friction on the ground causing the physics object to bounce.  Also, I can't seem to figure out how to apply a "forward" force instead of just a directional force.  I want to apply a force to go forward based on what direction I'm facing.

I'm hoping to be able to put a demo of what I've accomplished by the end of this weekend.

Thanks,

darkfrog