I can't jump it

First: I just wanted to give this topic a cool name.
Second: I can’t make my character jump!

from panda3d.core import loadPrcFileData

confVars = '''
window-title Forest Game
'''

loadPrcFileData('', confVars)

from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.interval.IntervalGlobal import Wait
from panda3d.core import CollisionTraverser, CollisionHandlerPusher
from panda3d.core import CollisionNode, CollisionSphere, CollisionInvSphere


class MyGame(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        self.disableMouse()
        
        self.cTrav = CollisionTraverser()
        
        pusher = CollisionHandlerPusher()
        pusher.setHorizontal(True)

        self.env = self.loader.loadModel("models/environment")
        self.env.setScale(0.25, 0.25, 0.25)
        self.env.setPos(-8, 42, -3)
        self.env.reparentTo(self.render)
        envBounds = self.env.getBounds()
        envCenter = envBounds.getCenter()
        envRad = envBounds.getRadius() * 0.7
        
        cNode = CollisionNode("environment")
        cNode.addSolid(CollisionInvSphere(envCenter, envRad))
        envC = self.render.attachNewNode(cNode)
        
        camBounds = self.camera.getBounds()
        camCenter = camBounds.getCenter()
        camRad = 5
         
        cNode = CollisionNode("camera")
        cNode.addSolid(CollisionSphere(camCenter, camRad))
        camC = self.camera.attachNewNode(cNode)
        camC.show()
        
        self.cTrav.addCollider(camC, pusher)
        pusher.addCollider(camC, self.camera)

        self.accept("w", self.__key, ["w"])
        self.accept("a", self.__key, ["a"])
        self.accept("s", self.__key, ["s"])
        self.accept("d", self.__key, ["d"])
        self.accept("space", self.__key, ["space"])
        self.accept("arrow_left", self.__key, ["left"])
        self.accept("arrow_right", self.__key, ["right"])
        
        self.taskMgr.add(self.jump, "jump")
    
    def jump(self, task):
        if self.camera.getZ() == 2:
            Wait(5)
            self.camera.setZ(0)
        
        return Task.cont

    def __key(self, key):
        if key == "w":
            self.camera.setY(self.camera, 2)
        elif key == "a":
            self.camera.setX(self.camera, -2)
        elif key == "s":
            self.camera.setY(self.camera, -2)
        elif key == "d":
            self.camera.setX(self.camera, 2)
        elif key == "space":
            self.camera.setZ(2)
        elif key == "left":
            self.camera.setH(self.camera, 2)
        elif key == "right":
            self.camera.setH(self.camera, -2)

game = MyGame()
game.run()

If the code in your task runs at all (because comparing two floating-point values for exact equality cannot be relied on), the Wait(5) does nothing, because you’re just creating an interval and doing nothing with it.

You probably want to check how much time has elapsed within the task (you could store the current time when you start jumping) and doing your action based on that. Or, you could use intervals to handle the movement.

So you mean something like:

Sequence(Wait(5)).start()

?

That will start the interval at least, but the code after that start() will still run right away.

If you want something to be run after the Wait is complete, you have to add a Func to your sequence.

So like:

Sequence(Wait(5), Func(self.camera.setZ, (0))).start()

Right?

For example, yes. Don’t forget the .start().

Yeah sorry. I forgot to type that part.