physics engine: impulse

Thanks for the example!

I got a couple of errors, one was presumable because the models which come with panda have changed (box is clearly too small but it works) and the other due to late initialization of the particle system. Here is a diff (simple fix but maybe someone will find it useful :slight_smile:):


*** 56,66 ****
self.plight.setAttenuation(Point3(0,0.2, 0))
self.plnp = render.attachNewNode(self.plight)
render.setLight(self.plnp)

      #object to apply a force to

! self.cubeBoy = loader.loadModel(‘1cube’)

      #'camera'
      base.oobe()
      base.disableMouse()
      self.camDist =20

— 56,66 ----
self.plight.setAttenuation(Point3(0,0.2, 0))
self.plnp = render.attachNewNode(self.plight)
render.setLight(self.plnp)

      #object to apply a force to

! self.cubeBoy = loader.loadModel(‘box’)

      #'camera'
      base.oobe()
      base.disableMouse()
      self.camDist =20

*** 151,160 ****
— 151,164 ----
self.totalImpulse = self.totalPImpulse + self.totalNImpulse

  def setupForce(self):
  •     # This method must be called to enable the task that computes the
    
  •     # PhysicsManager every frame. 
    
  •     base.enableParticles()
    
  •     # The physical object, that is, the object which is acted upon by
        # the physics system, needs an ActorNode to define the coordinate
        # system in which it is moving, and to manifest the object's
        # actions. 
        self.an = ActorNode('actor node')
    

*** 175,188 ****

      # We need to attach it to a PhysicsManager to do the actual work
      # of moving it around. 
      base.physicsMgr.attachPhysicalNode(self.an)
  •     # This method must be called to enable the task that computes the
    
  •     # PhysicsManager every frame. 
    
  •     base.enableParticles()
    
  •     # Now apply a force to the ActorNode.  The Force needs a
        # ForceNode, to define the coordinate system in which it is
        # applied.
        self.fn = ForceNode('pull')
        self.fnp = render.attachNewNode(self.fn)
    

— 179,188 ----