[Solved] First-person Camera Bobbing

How can I set up my camera to bob unlike the jmonkeyengine default camera? I currently have no camera code so I would like to set it up to make it bob in the beginning.

Be careful with bobbing as it is really easy to cause motion sickness in a good % of your potential players (even if it doesn’t cause it in you it may well cause it in others). You may need to create your own camera to do this as it’s not a feature I’ve seen in the standard cameras. Someone else may have a suggestion though…

It’s not even really a camera problem though you can fake it that way with a simple sin/cos wave… you will still need to separate player position from camera position in some way. The camera then becomes an offset from player position and the normal camera controls move the player. You can encapsulate this into a camera or you can treat them separately. There is no one size fits all… though if the player’s feet ever leave the ground (like for jumping or falling) then having them separate might make it easier to keep the head from bobbing during flight.



Either way, if the math to bob the camera seems difficult then you may want to swing back and do this later. The math is pretty basic and you’ll have 100 more interesting problems to tackle in the mean time.

I plan on making the bobbing optional. Could you explain to me more about the sin/cos wave thing?

@ifence9, if I understand correctly, you want something similar to this: http://www.wolframalpha.com/input/?i=y+%3D+sin+x



A sin/cos wave gives a bobbing effect. Again, I hope I understood what you want. To implement it, you must move the camera by calculating a sine wave.



EDIT: If I might add a suggestion: use the bobbing effect sparingly to give a good effect. Don’t do this repeatedly - even if the user chooses the option for the bobbing effect. I don’t know what you have in mind, but it would induce dizziness, and users might not take that kindly and choose the non-bobbing option.



What do I mean by sparingly? Only bob the camera when a player is sprinting, rather than running, for example.

Since I have been getting a lot of that about the bobbing not being good I guess I will remove it. Thank you all for the help though. You can see updates about my game here: flashc0d3r.tumblr.com

It’s an effect that can work well - but needs to be used sparingly and in the right way.

Yeah, head bobbing is fine. It’s one of those things where less is more so don’t bob too drastically and don’t roll your bob as that’s the one that will really make people sick.

or bob excessively then give the game free to your enemies

2 Likes

I achieved ‘bob’ by simply aligning the camera to the head bone of my model…



http://www.youtube.com/watch?v=gWMLwXeqm9U

1 Like

@thetoucher could you please explain this better? Do you mean the bone for animation? And how would you go about binding the camera to it?

@ifence9 sure thing. I have an animated character , playing a walking animation (you can kind of see it here ), and every frame I move the camera to where the animated head bone position is.



This is what I use to position the camera, may help :

[java]cam.setLocation(

this.actor.getSpatial().getLocalRotation().mult(headBone.getModelSpacePosition())

.add(actor.getSpatial().getWorldTranslation())

);[/java]

1 Like
@thetoucher said:
@ifence9 sure thing. I have an animated character , playing a walking animation (you can kind of see it here ), and every frame I move the camera to where the animated head bone position is.

This is what I use to position the camera, may help :
[java]cam.setLocation(
this.actor.getSpatial().getLocalRotation().mult(headBone.getModelSpacePosition())
.add(actor.getSpatial().getWorldTranslation())
);[/java]

Where you say .mult(headBone.getModelSpacePosition) is the headBone a part of the model that is referenced? Also, all the spatial's, are those called from another part of the script?
@ifence9 said:
Where you say .mult(headBone.getModelSpacePosition) is the headBone a part of the model that is referenced? Also, all the spatial's, are those called from another part of the script?

Script? You are aware that you need at least basic java knowledge to use jme? Its not really ideal starting to learn java with something complicated as game programming.

I have used java programming before and have programmed 3d games before.

2 Likes
@ifence9 said:
Where you say .mult(headBone.getModelSpacePosition) is the headBone a part of the model that is referenced?

- yep, its a com.jme3.animation.Bone, which was setup in Blender as part of the animation rig.
@ifence9 said:
Also, all the spatial's, are those called from another part of the script?

- actor.getSpatial() is a reference to the imported character mesh.
1 Like

Ahhhhh…thank you for the help. Now I just have to wait for my graphic design team to get the models done for me.