Aurilliance and Lethe, thank you both for the replies and offers.
I suppose I should describe my goal in this before going further. I am trying to accomplish a sort of ‘free flight’ movement primarily. While moving around on the surface of the terrain and jumping would be great for terrestrial movement, (which is another part of my goal,) my question is–can the same mechanics be used for free flight? By “free flight,” think a combination of aeroplane and VTOL; hovering, lifting and falling, forward and reverse, strafing, rotation–you get the idea. This is why I was thinking in terms of applying forces.
Lethe, perhaps I am misinterpreting; are you suggesting I simply bruteforce the changing velocity by applying physics equations? If that is the case, then what would be the point of having actual “forces” that can be applied to the physical objects? It seems rather like doing it the old way without ODE implementation, which at best would also include manual acceleration and such. I just figured that ODE’s forces would make the job that much easier; though, as I said before, I lack experience with the system. Would manually handling the velocities work better for the goal I laid out above?
By the way, to add to my response to Pro-rsoft, I removed the key-press condition and just put self.ball.body.addForce(0.0,0.0,10.0) into a task that started right away. Still, nothing happened. I figure–maybe I should post some code as I may have skipped a critical step.
The following is the ball class that would become the character class later:
class Ball():
def __init__(self, world):
# Load the model
self.model = loader.loadModel('smiley')
self.model.flattenLight()
self.model.setTextureOff()
# Create the nodepath
self.np = self.model.copyTo(render)
self.np.setPos(0.0, 0.0, 20.0)
self.np.setHpr(0.0, 0.0, 0.0)
# Create the body and set the mass
self.body = OdeBody(world.world)
M = OdeMass()
M.setSphere(50, 1)
self.body.setMass(M)
self.body.setPosition(self.np.getPos(render))
self.body.setQuaternion(self.np.getQuat(render))
# Create the geom
self.geom = OdeSphereGeom(world.space, 1)
self.geom.setCollideBits(BitMask32(0x00000001))
self.geom.setCategoryBits(BitMask32(0x00000001))
self.geom.setBody(self.body)
The following is the main class that starts the whole program:
class Main(DirectObject):
def simulationTask(self, task):
self.world.space.autoCollide() # Setup the contact joints
# Step the simulation and set the new positions
self.world.world.quickStep(globalClock.getDt())
if not self.ball.np.isEmpty():
self.ball.np.setPosQuat(render, self.ball.geom.getBody().getPosition(), Quat(self.ball.geom.getBody().getQuaternion()))
self.world.contactgroup.empty() # Clear the contact joints
return task.cont
def lift(self, flag):
self.liftValue = flag
def move(self, task):
if self.liftValue:
self.ball.body.addForce(0.0, 0.0, 10.0)
return task.cont
def __init__(self):
self.liftValue = 0
self.accept('escape', sys.exit)
self.accept('q', self.lift, [1])
self.accept('q-up', self.lift, [0])
self.world = World()
self.ball = Ball(self.world)
taskMgr.doMethodLater(0.5, self.simulationTask, 'Physics Simulation Task')
taskMgr.add(self.move, 'Character Movement Task')
run()
And then of course I start it up by creating a Main() object. Oh, and I added the key-press condition back into it since I know that as ugly as it looks now, (I will change it to the traditional keymap dictionary,) it does function as it’s supposed to. I know this because, as I wrote in my original post, replacing the addForce() with setLinearVel() showed a visible change while the key was being held down.
I doubt the World() class code would help much since obviously whatever ODE-related stuff in there works properly as can be observed with the ball falling and colliding with the terrain. It really only contains just that; loading the terrain and setting it up with the ODE world and space.