GeoMipTerrain Issue [solved, I think]

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?

i usually send a ray down from the character, if the ray doesnt hint anything i apply a upward force or do another raycast with a line. this way a character cannot fall of the terrain, or at least can walk back onto the terrain again. if he’s going below terrain he will be set back by the code or slowly moves upwards until he reaches it.

Well i am using a collision ray but because the panda starts below the ground he dosnt get pushed back up… I dont know if i did something wrong as i took the collision ray from roaming ralph. I think that when i generate the panda i need a dynamic z point to put him on (equal to the ground) but I dont know how to do that.

time to add changes due to Craig and me talking on IRC I found out that collisions may not be the best way to do this so i decided to try GetElevation instead. here is the code:

pandaStartPosX = 0
pandaStartPosY = 0
pandaStartPosZ = terrain.getElevation(pandaStartPosX, pandaStartPosY) * root.getSz()
pandaActor = Actor.Actor("models/panda-model",{"walk":"models/panda-walk4"})
pandaActor.reparentTo(render)
pandaActor.setScale(0.005,0.005,0.005)
pandaActor.setPos(pandaStartPosX, pandaStartPosY, pandaStartPosZ)

Now the problem I am having is that when i run this code my panda is now way above the ground due to it taking the max height of the terrain due to root.getSz. so if root.getSz is anything but 0 my panda will not be on the ground.

edit: I cleaned up the code a but still same problem

How do i fix this?

I figured it out!

It was not sitting on the ground because my panda was at 0,0,0 it was getting the Z info for 0,0,0 for the terrain but i moved the terain -50,-50,0 so the terrain was in the wrong spot i put the terrain back and now it works!!!