Move a 3d model in a terrain .bam file

OK, can anyone compile some code that moves the object in the terrain I need help with this, I don’t know panda3d and I’m going to make a Car game. and after showing the code can you show some code on how to do this but with animation in the file type of .obj .blend .fbx.Please #PYTHON

One of the sample-programs shows this! If you look at the “Roaming Ralph” sample, you should find code that moves a character over uneven terrain, and that animates the character in doing so.

(I will note that its approach to collisions with obstacles is not great, but you can perhaps look to other sources when you get to that point in your own project.)

[edit] In case you haven’t yet seen the sample-programs, you should find them amongst the links on the download page.

Wait you mean like it’s gonna ,say if ‘ralph’ is climbing a mountain he will look like he’s walking straight instead of tilting the body like he is climbing a mountain

I… don’t think that I addressed something along those lines, no.

What you’re describing there would likely be largely a matter of appropriate animations (whether hand-made, procedural, or a bit of both), I would think.

are you saying that it wont look like that

I believe that Roaming Ralph taking a very simple approach: Ralph stays vertical, regardless of slope, and has only one animation for walking, regardless of slope.

Now, you could change the code such that your character is tilted when climbing. But that won’t look like they’re climbing a mountain, because when a human climbs a mountain they don’t simply rotate their body–the way that they move changes, too. At the least their feet will be at a different angle relative to their legs, and I daresay that likely the movement of those legs will change, too, and perhaps other elements of their posture and movement, too. This, then, seems likely to be implemented via additional animations, or perhaps via procedural animation.

All that said… looking back, you indicated that you’re making a car-game. If your player-character is represented by a car, then additional animations are unlikely to be called for: cars don’t change the way that they move overmuch, I daresay!

Still, you might well want to add some code to adjust the vehicle’s angle on sloped surfaces, indeed.

i know but they will rotate a tiny bit

the approach of the car games is that if you go on this coordinate your 3d model will look like (which is the tilted thing) this

and what if you add some kind of border on some road or places will panda3d’s physics engine do the trick of tilting.

First, let me note that Panda has both a built-in collision system and a built-in physics system; while related and to some degree overlapping, they’re not quite the same, I believe. I’ll confess that while I’m familiar with the collision system, I’m not familiar with the physics system.

So, I’m not sure of what the physics system, specifically, does in such circumstances, I’m afraid.

The collision system, on the other hand, doesn’t automatically do what you ask, as far as I’m aware. However, you could write code that uses the collision system to so tilt your car, I do believe.

There are generally two ways to do physics on a character controller in Panda – the BulletVehicle and the BulletCharacterControllerNode.

The BulletVehicle is just what it sounds like – a way to simulate a vehicle’s suspension, tires, and body weight. Tilting can be simulated “automatically” in this manner, dependent on how you set your BulletVehicle suspension up.

As for the Bullet CCN, there are a number of methods you can set, such as set_max_slope() BulletCharacterControllerNode — Panda3D Manual

I imagine tilting with a first-person character would be largely a matter of custom camera handling, rather than something you’d need physics for.

In all fairness, a simpler simulation can be made, whether using Bullet or Panda’s built-in systems, I do believe.

Much depends, I think, on the detail that the simulation is intended to have.

its beyond me now, its more likely to use the coordinate system,

lets anyway go to the original topic------
say i convert my terrain in blender to .bam file how do i use a .blend model in it like moving it,EXAMPLE NOT WHAT I REALLY WANT TO SAY-- say like i have ‘roaming ralph’ but just that i changed the model to my own model, how do i use my terrain in it.

thank ya

if you guys help i’ll thank you guys so much that even in the credits of the car game i might add your names and even a “made with python and panda3d”

(might not be true)

I’m not entirely sure that I understand what it is that you’re asking–are you asking how to use multiple model-files in a single game?

If so, then it’s simply a matter of loading multiple models and storing them in separate variables, I believe.

Your problem is that you want to make games, but you don’t want to study samples and read the documentation.

I changed the bullet sample 18_Vehicle.

#from pandac.PandaModules import loadPrcFileData
#loadPrcFileData('', 'load-display tinydisplay')

import sys
import direct.directbase.DirectStart

from direct.showbase.DirectObject import DirectObject
from direct.showbase.InputStateGlobal import inputState

from panda3d.core import AmbientLight
from panda3d.core import DirectionalLight
from panda3d.core import Vec3
from panda3d.core import Vec4
from panda3d.core import Point3
from panda3d.core import TransformState
from panda3d.core import BitMask32
from panda3d.core import Filename
from panda3d.core import PNMImage

from panda3d.bullet import BulletWorld
from panda3d.bullet import BulletPlaneShape
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletRigidBodyNode
from panda3d.bullet import BulletDebugNode
from panda3d.bullet import BulletTriangleMesh
from panda3d.bullet import BulletTriangleMeshShape
from panda3d.bullet import BulletVehicle
from panda3d.bullet import ZUp

class Game(DirectObject):

  def __init__(self):
    base.setBackgroundColor(0.1, 0.1, 0.8, 1)
    base.setFrameRateMeter(True), -20, 4), 0, 0)

    # Light
    alight = AmbientLight('ambientLight')
    alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
    alightNP = render.attachNewNode(alight)

    dlight = DirectionalLight('directionalLight')
    dlight.setDirection(Vec3(1, 1, -1))
    dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
    dlightNP = render.attachNewNode(dlight)


    # Input
    self.accept('escape', self.doExit)
    self.accept('r', self.doReset)
    self.accept('f1', self.toggleWireframe)
    self.accept('f2', self.toggleTexture)
    self.accept('f3', self.toggleDebug)
    self.accept('f5', self.doScreenshot)

    inputState.watchWithModifiers('forward', 'w')
    inputState.watchWithModifiers('left', 'a')
    inputState.watchWithModifiers('reverse', 's')
    inputState.watchWithModifiers('right', 'd')
    inputState.watchWithModifiers('turnLeft', 'q')
    inputState.watchWithModifiers('turnRight', 'e')

    # Task
    taskMgr.add(self.update, 'updateWorld')

    # Physics

  # _____HANDLER_____

  def doExit(self):

  def doReset(self):

  def toggleWireframe(self):

  def toggleTexture(self):

  def toggleDebug(self):
    if self.debugNP.isHidden():

  def doScreenshot(self):

  # ____TASK___

  def processInput(self, dt):
    engineForce = 0.0
    brakeForce = 0.0

    if inputState.isSet('forward'):
      engineForce = 3000.0
      brakeForce = 0.0

    if inputState.isSet('reverse'):
      engineForce = 0.0
      brakeForce = 100.0

    if inputState.isSet('turnLeft'):
      self.steering += dt * self.steeringIncrement
      self.steering = min(self.steering, self.steeringClamp)

    if inputState.isSet('turnRight'):
      self.steering -= dt * self.steeringIncrement
      self.steering = max(self.steering, -self.steeringClamp)

    # Apply steering to front wheels
    self.vehicle.setSteeringValue(self.steering, 0);
    self.vehicle.setSteeringValue(self.steering, 1);

    # Apply engine and brake to rear wheels
    self.vehicle.applyEngineForce(engineForce, 2);
    self.vehicle.applyEngineForce(engineForce, 3);
    self.vehicle.setBrake(brakeForce, 2);
    self.vehicle.setBrake(brakeForce, 3);

  def update(self, task):
    dt = globalClock.getDt()

    self.processInput(dt), 10, 0.008)

    #print self.vehicle.getWheel(0).getRaycastInfo().isInContact()
    #print self.vehicle.getWheel(0).getRaycastInfo().getContactPointWs()

    #print self.vehicle.getChassis().isKinematic()

    return task.cont

  def cleanup(self): = None

  def setup(self):
    self.worldNP = render.attachNewNode('World')

    # World
    self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug')) = BulletWorld(), 0, -9.81))

    # Added for demonstration as an answer for the forum.
    terrain = base.loader.loadModel("landscape.bam")
    terrain.setPos(0, 0, -17)

    mesh = BulletTriangleMesh()

    for node_path in terrain.findAllMatches( '**/+GeomNode' ):
        for i in range(node_path.node().getNumGeoms()):
            geom = node_path.node().getGeom(i)
    shape = BulletTriangleMeshShape(mesh, True)

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Landscape'))
    # --------------------------------------------

    # Chassis
    shape = BulletBoxShape(Vec3(0.6, 1.4, 0.5))
    ts = TransformState.makePos(Point3(0, 0, 0.5))

    np = self.worldNP.attachNewNode(BulletRigidBodyNode('Vehicle'))
    np.node().addShape(shape, ts)
    np.setPos(0, 0, 1)


    # Vehicle
    self.vehicle = BulletVehicle(, np.node())

    self.yugoNP = loader.loadModel('models/yugo/yugo.egg')

    # Right front wheel
    np = loader.loadModel('models/yugo/yugotireR.egg')
    self.addWheel(Point3( 0.70,  1.05, 0.3), True, np)

    # Left front wheel
    np = loader.loadModel('models/yugo/yugotireL.egg')
    self.addWheel(Point3(-0.70,  1.05, 0.3), True, np)

    # Right rear wheel
    np = loader.loadModel('models/yugo/yugotireR.egg')
    self.addWheel(Point3( 0.70, -1.05, 0.3), False, np)

    # Left rear wheel
    np = loader.loadModel('models/yugo/yugotireL.egg')
    self.addWheel(Point3(-0.70, -1.05, 0.3), False, np)

    # Steering info
    self.steering = 0.0            # degree
    self.steeringClamp = 45.0      # degree
    self.steeringIncrement = 120.0 # degree per second

  def addWheel(self, pos, front, np):
    wheel = self.vehicle.createWheel()


    wheel.setWheelDirectionCs(Vec3(0, 0, -1))
    wheel.setWheelAxleCs(Vec3(1, 0, 0))


game = Game()

After spending five minutes on it. (1.6 MB)

1 Like

uhh-- that’s not what I’m trying to say its basically like doing the blend2bam but after the step, I want it move it in a terrain