Physics and camera behavior

What I'm trying to do is tie the camera with the physics engine. I don't need springs or joints or anything else at this point. Just the camera not going through the floor or the walls.

The behavior I'm looking for is the first person camera not going through objects and the like but not bouncing around or speeding up or anything else I get when I play with the physics engine.

I have a simple sphere as my dynamic node. Really I'd like to just move the camera with it tied to the dynamic node.

I tried to do a before step and after step with the physics engine, moving the dynamic node to the camera and then for the after step the camera moving to the dynamic node but that didn't seem to work. The camera just sat there.

Is this possible or do I need to rethink it?


Of course, you can do that. I would use a DynmicPhysicsNode with a PhysicsCollisionGeometry (e.g. a sphere) and a CameraNode attached to it. This DPN should not be affected by gravity. Then tie that node to a modified PhysicsPicker which does not react on mouse events but on the camera controls.

If PhysicsPicker looks too complicated for you, you can move it by setting velocities for an easy start. This will result in some jitter when trying to move through things or dynamic stuff is hitting your cam geom. But when you are familiar with the physics stuff you can switch to joints (PhysicsPicker-like) later on.

Thank you. I had not looked at PhysicsPicker and will do so.

Finally got around to working on this. Seems like this is the way to go.

However, while moving around the environment I get the following error:

ODE Message 2: cforce has NaN component! (....odesrcquickstep.cpp:770)

A couple of times and then the game will crash and produce a log file:

# An unexpected error has been detected by HotSpot Virtual Machine:
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c91166b, pid=3740, tid=3756
# Java VM: Java HotSpot(TM) Client VM (1.5.0_08-b03 mixed mode)
# Problematic frame:
# C  [ntdll.dll+0x1166b]
# An error report file with more information is saved as hs_err_pid3740.log
# If you would like to submit a bug report, please visit:

Any ideas on what's going on?
kc5uyn said:
while moving around the environment

Do you mean moving around static physics nodes? If yes: don't do that :P
The message could mean that forces became too large. You need to avoid that. Not sure what caused it, if you did not move static nodes, though. Could be improper joint combination as well.

No I'm not moving the static node.

What would be an improper joint combination? I'm attaching one joint to the dynamic node when I want to move it and detach it when I'm not moving - just as in the PhysicsPicker.

Problematic joint combinations could be things like two fixed joints attached to the same dpn pulling it into opposite directions. Or a collision with a static node while a joint tries to pull the dpn through the static node, etc.

So actually… it can be anything that confuses ODE :expressionless:

I think the problem has to do with the environment I'm loading in and the speed of the ball I'm moving around. Still playing with it. But this anchor stuff is very nice and exactly what I needed.

Is there a way to turn off reactions to collisions except for gravity? For example, if I'm walking into a wall and stop (detach the anchor) the ball will start moving away from the wall when I just want it to stop dead. I put an after step check to clear dynamics on the node if I'm not moving the player but this doesn't seem to stop it immediately and affects gravity.


kc5uyn said:

Is there a way to turn off reactions to collisions except for gravity?

No. Collisions are triggered by position not by speed or force (in ODE). You could put the dpn to rest(). But that may have unwanted effect when the dpn starts moving again.
What about keeping the joints, even if the player control is released?