Jitter with gravity

Hi all,

I’m getting some mad jitter in my game since adding gravity. At first, I thought it might have been my update player routine - so I commented that out (stationary player), same result.

So I pondered by update camera routine - but that also looks fine.

Then I pondered my collision handling, disabled that, no luck.

…and now I’m guessing I’ve just done something dumb in the code… :slight_smile:

Physics setup:

    def setupPhysics(self):
        base.enableParticles() # enables physics

        # create a physics node, put in a node path, parent with player
        Node = NodePath(PandaNode("PhysicsNode"))
        Node.reparentTo(self.render)
        an = ActorNode("player-physics")
        # an.getPhysicsObject().setMass(1361.077)
        anp = Node.attachNewNode(an)
        self.player.reparentTo(anp)

        # create a force (gravity)
        gravityFN = ForceNode('world-gravity')
        gravityFNP = self.render.attachNewNode(gravityFN)
        gravityForce = LinearVectorForce(0,0,-0.81)
        gravityFN.addForce(gravityForce)

        base.physicsMgr.attachPhysicalNode(an)
        base.physicsMgr.addLinearForce(gravityForce)

And the camera:

    def updateCamera(self):
        # player flies faster - camera backs off
        percent = (self.speed/self.maxspeed)
        self.camera.setPos(self.player, 19.6225+(10*percent), 3.8807, 10.2779)
        self.camera.setHpr(self.player,94.8996,-12.6549, 1.55508)

Any ideas?

Cheers,
Gary

Huh, I also note that the acceleration just keeps on coming… the longer I play the faster I drop.

Somehow think I’m using the completely wrong approach for a flight game! lol

~G

Are you using a PhysicsCollisionHandler, and not just a CollisionHandlerPusher? A PhysicsCollisionHandler will act like a regular pusher, but also stop the acceleration from physics. Otherwise your object will keep accelerating even when it’s sitting on the floor, until it eventually busts through.

David

Um, I’m not using either. My collisions:

    def setupCollisions(self):
        self.collTrav = CollisionTraverser()

        self.playerGroundSphere = CollisionSphere(0,1.5,-1.5,1.5)
        self.playerGroundCol = CollisionNode('playerSphere')
        self.playerGroundCol.addSolid(self.playerGroundSphere)

        # bitmasks       self.playerGroundCol.setFromCollideMask(BitMask32.bit(0))
        self.playerGroundCol.setIntoCollideMask(BitMask32.allOff())
        self.world.setCollideMask(BitMask32.bit(0))
        self.water.setCollideMask(BitMask32.bit(0))

        # and done
        self.playerGroundColNp = self.player.attachNewNode(self.playerGroundCol)
        self.playerGroundHandler = CollisionHandlerQueue()
        self.collTrav.addCollider(self.playerGroundColNp, self.playerGroundHandler)

        # DEBUG as per video:
        if (self.debug == True):
            self.playerGroundColNp.show()
            self.collTrav.showCollisions(self.render)

Cheers,
~G

Since you’re rolling your own collision reaction, you’ll have to deal with the physics too. Whenever you detect a collision, remember to set your physics object’s velocity to 0.

David

Ah, I see. Thanks David, you are wealth of information. :slight_smile:

Cheers,
Gary