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?
Thanks in advance,
Thomas
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.task import Task
base.enableParticles()
force = LinearVectorForce( 0.0, 5.0, 0.0 )
actorNode = ActorNode( "root" )
actorNode.getPhysical(0).addLinearForce( force )
actorNodePath = NodePath( actorNode )
forceNode = ForceNode( "forceNode" )
forceNode.addForce( force )
actorNodePath.attachNewNode( forceNode )
base.physicsMgr.attachPhysicalnode( actorNode )
model = loader.loadModel( "smiley" )
model.reparentTo( actorNodePath )
actorNodePath.reparentTo( render )
def turnTask( task ):
actorNodePath.setH( actorNodePath.getH() + 120 * globalClock.getDt() )
return Task.cont
taskMgr.add( turnTask, "turn-task" )
run()