Ok so im using GeoMipterrain and until now it is going well! so lets start with the terrain code:
#Load the first environment model
terrain = GeoMipTerrain("ground")
terrain.setHeightfield(Filename("game heightmap.bmp"))
terrain.setBruteforce(True)
# Set terrain properties
terrain.setBlockSize(32)
terrain.setNear(40)
terrain.setFar(100)
terrain.setFocalPoint(base.camera)
terrain_tex = loader.loadTexture('ground.jpg')
# Store the root NodePath for convenience
root = terrain.getRoot()
root.reparentTo(render)
ts = TextureStage('ts')
root.setSz(10)
root.setPos(-50,-50,0)
root.setTexScale(ts.getDefault(),10,10)
root.setTexture(terrain_tex,1)
terrain.getRoot().reparentTo(render)
def updateTask(task):
terrain.update()
return task.cont
taskMgr.add(updateTask, "update")
This works well for placing a chunk of land down (I plan on adding more but for now just a 1000X1000 seems good)
Next I need to add a character
#Load the panda actor, and loop its animation
pandaActor = Actor.Actor("models/panda-model",{"walk":"models/panda-walk4"})
pandaActor.setScale(0.005,0.005,0.005)
pandaActor.reparentTo(render)
#pandaActor.loop("walk")
Ok so i stole this char from Hello world Panda! but its a start to get things working.
then I went and used code so my panda wouldnt fall though terrain (I hoped this would correct the issue of the panda begin below the ground)
#testing collision rays
cTrav = CollisionTraverser()
pandaGroundRay = CollisionRay()
pandaGroundRay.setOrigin(0,0,1000)
pandaGroundRay.setDirection(0,0,-1)
pandaGroundCol = CollisionNode('pandaRay')
pandaGroundCol.addSolid(pandaGroundRay)
pandaGroundCol.setFromCollideMask(BitMask32.bit(0))
pandaGroundCol.setIntoCollideMask(BitMask32.allOff())
pandaGroundColNp = pandaActor.attachNewNode(pandaGroundCol)
pandaGroundHandler = CollisionHandlerQueue()
cTrav.addCollider(pandaGroundColNp, pandaGroundHandler)
# Uncomment this line to see the collision rays
#pandaGroundColNp.show()
#Uncomment this line to show a visual representation of collisions occuring
#cTrav.showCollisions(render)
#Saves Panda's start postion incase he falls off map
startpos = pandaActor.getPos()
#if Panda tries to fall through ground update it
entries = []
for i in range(pandaGroundHandler.getNumEntries()):
entry = pandaGroundHandler.getEntry(i)
entries.append(entry)
entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
x.getSurfacePoint(render).getZ()))
if (len(entries)>0) and (entries[0].getIntoNode().getName() == "ground"):
pandaActor.setZ(entries[0].getSurfacePoint(render).getZ())
else:
pandaActor.setPos(startpos)
That was taken from roaming ralph and modded to use in my script but it appears that my panda is already below land so nothing corrects. I want to add movement in but until I get the panda on the ground im stuck. If you notice any problems in the code I posted or something im missing let me know!
So i guess what i am trying to say is how can i get my panda above ground?