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"))
# Set terrain properties
terrain_tex = loader.loadTexture('ground.jpg')
# Store the root NodePath for convenience
root = terrain.getRoot()
ts = TextureStage('ts')

def updateTask(task):
  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"})

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()
pandaGroundCol = CollisionNode('pandaRay')
pandaGroundColNp = pandaActor.attachNewNode(pandaGroundCol)
pandaGroundHandler = CollisionHandlerQueue()
cTrav.addCollider(pandaGroundColNp, pandaGroundHandler)

# Uncomment this line to see the collision rays
#Uncomment this line to show a visual representation of collisions occuring

#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.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
if (len(entries)>0) and (entries[0].getIntoNode().getName() == "ground"):

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.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!!!