Applying local forces to ActorNodes?

How do I apply a force to an ActorNode in its local coordinate system? Say I want a constant force applied in its forward direction, such that the ActorNode moves in a different direction when its heading is changed.

Below is a snipplet of code illustrating what I’m trying to do. I have a task set up to rotate the ActorNode each frame. I’d like the ActorNode to change direction according to the heading, instead of travelling in a constant direction. What am I overlooking?

Thomas

``````import direct.directbase.DirectStart
from pandac.PandaModules import *

base.enableParticles()

force = LinearVectorForce( 0.0, 5.0, 0.0 )

actorNode = ActorNode( "root" )
actorNodePath = NodePath( actorNode )

forceNode = ForceNode( "forceNode" )
actorNodePath.attachNewNode( forceNode )

base.physicsMgr.attachPhysicalnode( actorNode )

model.reparentTo( actorNodePath )
actorNodePath.reparentTo( render )

actorNodePath.setH( actorNodePath.getH() + 120 * globalClock.getDt() )

run()``````

It appears you have discovered a bug in the physics system. We will try to get the fix in for the upcoming 1.0.1 release.

In the meantime, there are two possible workarounds:

(1) Since the bug affects local forces, not global forces, you can fix it by making the force a global force, e.g. by calling base.physicsMgr.addLinearForce( force ) instead of actorNode.getPhysical(0).addLinearForce( force ). This does mean that the force will affect all objects in the world, though, so this workaround only works if your actor is the only object in the world.

(2) Alternatively, I think you can work around the bug by keeping the force as a local force, but introducing a new dummy node that you parent your ActorNode to, and applying the rotation to that node, instead of to the ActorNode. The bug is revealed only when there is a rotation on the ActorNode itself.

Or you can just wait for 1.0.1.

David