Need help with phisics (making player jump)

I’m using the FPS() class found here

I’m trying to get the player to jump,

   def jumpUpdate(self,task):
       """ TODO make the player jump  """ 
       if self.readyToJump: 
           self.jump = 1 
           self.player.addLinearForce( LinearVectorForce(0.0, 0.0, 60.0))
           self.player.removeLinearForce( LinearVectorForce(0.0, 0.0, 60.0))
           self.player.addLinearForce( LinearVectorForce(0.0, 0.0, 0.0)) 
       return task.cont

it keeps saying AttributeError: ‘DynamicEntity’ object has no attribute ‘removeLinearForce’

Can someone help me?

I really need an answer

There is no DynamicEntity.removeLinearForce:

class DynamicEntity(Entity): 
   forceNode = 0 
   actorNode = 0 

   def __init__(self): 
      self.actorNode = ActorNode("DynamicEntity") 
      # init collision 
      self._collisionHandler = PhysicsCollisionHandler() 
      base.cTrav = CollisionTraverser() 
   def createForceNode(self): 
      # set up the ForceNode. This contains all the forces that 
      # act on this Entity. 
      self.forceNode = ForceNode("ForceNode") 
      self.attachNewNode( self.forceNode ) 
      base.physicsMgr.attachPhysicalnode( self.actorNode ) 
   def addLinearForce( self, force ): 
      if ( self.forceNode == 0 ): 
      self.forceNode.addForce( force ) 
      base.physicsMgr.addLinearForce( force ) 

   def setCollisionSolid( self, solid ): 
      collNodePath = Entity.setCollisionSolid( self, solid ) 
      base.cTrav.addCollider( collNodePath, self.collisionHandler() ) 
      self.collisionHandler().addCollider( collNodePath, self ) 
   def collisionHandler(self): 
      return self._collisionHandler

I’m pretty sure that you don’t want to remove the force there anyways.

Well then how do I keep the player from just rising up continually?

You probably will have to define it in dynamic entity so that it calls the method on the underlying force node.

Do you mean defining removeLinearForce()?

Found a solution:

   def jumpUpdate(self,task):
       """ TODO make the player jump  """ 
       if self.readyToJump: 
           Sequence(Func(self.player.addLinearForce,LinearVectorForce(0,0,self.gravity*2)), Wait(.5), Func(self.player.addLinearForce,LinearVectorForce(0,0,-self.gravity*2))).start()
       return task.cont

still needs a jump filter though :slight_smile: