I hate to ask and I have looked through the tutorial on setting up ODE physics. I need some clarification because when I tried to integrate the code with my code I got several errors and such.
My Goal:
Add gravity to the actorPanda so the panda falls…that’s it. I just need some help navigating through that ODE physics tutorial because they generate a box and procedurally texture it. I wish they would have just loaded a model instead of generating random cubes
Thanks in advance and if someone could point me to a tutorial that maybe has this in there that would be great. (by tutorial I mean an example that uses ODE in the code)
here is my code ( I apologize in advance its really messy and I haven’t had time to clean it up. )
from math import pi, sin, cos
import math, sys
from pandac.PandaModules import Vec3, Vec4
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import Sequence
from panda3d.core import Point3
from pandac.PandaModules import OdeWorld, OdeSimpleSpace, OdeJointGroup
from pandac.PandaModules import OdeBody, OdeMass, OdeBoxGeom, OdePlaneGeom
from pandac.PandaModules import CardMaker, Quat
class Panda(ShowBase):
def __init__(self):
ShowBase.__init__(self)
#setup gravity and physics world using ODE
#gravity is standard earth gravity rounded two decimal places -9.81 units/second
# self.world = OdeWorld()
# self.world.setGravity(0,0,-9.81)
# self.space = OdeSimpleSpace()
# self.space.setAutoCollideWorld(self.world)
# self.contactGroup = OdeJointGroup()
# self.space.setAutoCollideJointGroup(self.contactGroup)
self.environ = self.loader.loadModel("models/environment")
self.environ.reparentTo(self.render)
self.environ.setScale(0.25,0.25,0.25)
self.environ.setPos(-8, 42, 0)
self.pandaActor = Actor("models/panda-model", {"walk": "models/panda-walk4"})
self.pandaActor.setScale(0.005,0.005,0.005)
self.pandaActor.reparentTo(self.render)
#ode stuff for the pandaActor
# self.pandaActor.flattenLight()
# self.pandaActorMass = OdeBody(self.world)
# self.pandaActorMass.setMass(50,1,1,1)
#ode physics setup simulation
# taskMgr.add(self.simulateTask, "simulate physics")
#------------------
#Movement of character sections
self.accept('w', self.walking_forward)
self.accept('w-up', self.stop_walking_forward)
self.accept('s', self.walking_backward)
self.accept('s-up', self.stop_walking_backward)
self.accept('a', self.turn, [ -1 ])
self.accept('a-up', self.stopTurn)
self.accept('d', self.turn, [ 1 ])
self.accept('d-up', self.stopTurn)
self.acceptOnce('escape', sys.exit)
#------------------
# def simulateTask(self, task):
# self.space.autoCollide()
# self.world.quickStep(globalClock.getDt())
# self.pandaActor.setPosQuat(render, self.pandaActor.getPosition(), Quat(self.pandaActor.getQuaterion()))
# self.contactGroup.empty()
# return Task.cont
def turn(self, direction):
taskMgr.add(self.turnTask, 'turnTask', extraArgs = [ direction ])
def turnTask(self, direction):
self.pandaActor.setH(self.pandaActor.getH()-direction)
return Task.cont
def stopTurn(self):
taskMgr.remove('turnTask')
def walking_forward(self):
self.pandaActor.loop("walk")
taskMgr.add(self.walking_forward_task, 'walking_forward_task')
def walking_forward_task(self, task):
distance = 0.025
angle = self.pandaActor.getH()*math.pi/-180
correction = math.pi/2
dx = distance * math.cos( correction + angle )
dy = distance * -math.sin( correction + angle )
self.pandaActor.setPos( Vec3( self.pandaActor.getX( ) + dx, self.pandaActor.getY( ) + dy, 0 ) )
return Task.cont
def walking_backward(self):
self.pandaActor.loop("walk")
taskMgr.add(self.walking_backward_task, 'walking_backward_task')
def walking_backward_task(self, task):
distance = 0.025
angle = self.pandaActor.getH()*math.pi/-180
correction = math.pi/2
dx = distance * math.cos( correction + angle )
dy = distance * -math.sin( correction + angle )
self.pandaActor.setPos( Vec3( self.pandaActor.getX() - dx, self.pandaActor.getY() - dy, 0))
return Task.cont
def stop_walking_forward(self):
self.pandaActor.stop()
taskMgr.remove('walking_forward_task')
def stop_walking_backward(self):
self.pandaActor.stop()
taskMgr.remove('walking_backward_task')
# def stop_walking(self):
# self.pandaActor.stop()
# taskMgr.remove('walking_task')
app = Panda()
app.run()