The documentation is rather sketchy here. I’ve got a 100x100 heightmap that is generated by my “terrain” module, which is passed into a GeoMipTerrain, transformed into a terrain, textured, and rendered.
terrain=maketerrain("fractal")
terrain.generate()
environ=terrain.getRoot()
grasstex = loader.loadTexture("grasstex.png")
grasstex.setWrapU(Texture.WMMirror)
grasstex.setWrapV(Texture.WMMirror)
grasstex.setAnisotropicDegree(32)
environ.setTexScale(TextureStage.getDefault(), 150, 150)
environ.setTexture(grasstex)
environ.reparentTo(render)
environ.setScale(20000,20000,20000)
environ.flattenLight()
environ.setPos(0,0,-3000)
Some of this is placeholder, such as the single texture. Anyway, my character has no collisions, and walks through the hills and whatnot generated by the terrain generator. I wanted to use the getElevation method to set the actor’s Z to the terrain’s Z at his current position, but am having trouble getting that worked out.
I read various forum posts and documentation and came up with this so far:
elevation=terrain.getElevation(base.camera.getX(),base.camera.getY())*environ.get_sz()
self.actor.setZ(elevation)
This particular code complains due to the lack of a get_sz() method, but in the documentation it is recommended to do almost this exact code to get the elevation… Confusing.
I realize that the X/Y of the camera will not be in pixel value, and will thusly break my code’s efficacy. How can I translate the character/camera’s current position into a pixel value on the heightmap?
Ideas? Suggestions?
This game is going to have very high-end options, and many other collisions by the time it is completed. What sort of system would you recommend for the absolute most realistic collision between models? Is there a literal volumetric model collision detection I could use, taking the entire shape of the model into account?