the reason why is you use positionentity there, with a fixed height over the terrain. You should make the height variable, something like
if keydown(201) then height#=height+1
...
positionentity obj,ex,terrainy(ex,0,ez) + height + 5,ez
...
if keydown(201) then height#=height+1
...
positionentity obj,ex,terrainy(ex,0,ez) + height + 5,ez
...