#The exact placement may depend on your
# purposes and project; what I believe that
# mean to convey by putting this line here
# is simply "not in the task".
lastPos = base.cam.getPos()
updateDistanceSquared = 64*64
#I'm squaring the distance above so that
# I can use the "lengthSquared" method
# below, which I imagine to be slightly
# cheaper than "length". The number "64"
# is arbitrary, and may vary according to
# your desires.
def updateTask(task):
pos = base.cam.getPos()
distSq = (pos - lastPos).lengthSquared()
if distSq > updateDistanceSquared:
lastPos = pos
terrain.update()
return task.cont
Add “self.”/“objectName.” and/or rename as appropriate to the structure of your program.
You need to put the camera node into the setFocalPoint, and in my case using 1025x1025 terrain I set near=256 and far=512, min_level=2,block_size=64
Also you don’t really need a task to call the terrain update in, you can call it from within your task that handles the camera movements for forward,backward,and side to side movements. That way you only do the distance checking when you need to, when the camera actually moves. My distance calculation is a little different, I only use the xy value, not z.
Thanks for the help, I tried playing around with it a bit more but couldn’t have any success in making it update properly. However I decided to go for the blocky minecraft sort of look so I’m not using L3DT now but have a python implementation of Perlin Noise and coloured tiles. But I’m running into a bit of a problem My actor sometimes goes through the ground if I run directly at a steep slope. I think it may be something to do with the edges of the triangles. Any idea how I would fix this?
As an alternative, against it becoming a problem again, I see that GeomMipTerrain has a method called “getElevation” - if you’re using the ray-collision method of keeping your character on the ground, you could perhaps switch to getElevation(x, y) where x and y are the respective x- and y- coordinates of your character as of that update.