Ok, new revision uploaded: download.
- Committed ynjh_jo’s above fix for the flickering DirectLabels
Running pandaSteer.py you shouldn’t see any other difference, but if you run terrain.py or the new scene.py you will see new stuff. This code is still very rough right now, so any pointers welcome:
-
perlin.py module – contains a couple of utility functions for producing Perlin noise using Panda’s Perlin2 class (thanks to Hypnos in this thread: discourse.panda3d.org/viewtopic.php?t=2648)
-
terrain.py module has been revised to be a little more object-oriented (new Terrain class), and now trees can be placed on the terrain using Perlin noise. You pass a parameter (a float from 0 to 1) determining how many trees a terrain model should have, and the exact number and placement of trees is computed using Perlin. Run terrain.py to see a demo with four terrain models each with different hilliness and trees values.
-
New scene.py module – a demo scene with terrain, trees, wandering non-player Ralph characters and a point-and-click controlled player character, and an EdgeScreenTracker camera following the player (camera code is from tiptoe, ynjh_jo and cyan in this thread: discourse.panda3d.org/viewtopic.php?t=2577)
The characters in the scene steer to avoid the trees and to remain on the island. Actually I think the Container object is not even positioned properly so they may wander off the island, but trust me this works if you just position the container right.
Another problem is that the fractal terrain has dips in it as well as hills, so I’ve had to float the terrain above the sea to prevent too many ‘lakes’ appearing where the terrain dips below sea level. The characters don’t avoid these lakes. Any ideas for how to get rid of unwanted lakes welcome. I’m thinking of trying out Panda’s PerlinNoise as a heightmap generator.
Although the characters do a fair job of steering around individual trees, they do not steer to avoid ‘forests’ (groups of trees). Instead of going round a forest they will thread their way through it, and since they can only really steer to avoid one obstacle at a time, they sometimes hit trees when there are many close together.
Since I’m using a blocky, grid-like terrain map (and you might notice that I place every tree in the centre of one of the maps quads and have only one tree per quad) a good solution to this might be a simple pathfinding algorithm. Simply represent each quad of the terrain in a 2D list as True (you can walk here) or False (for some reason you can’t walk here, e.g. there is a tree in this quad). Then run an A* search over this grid to find paths from A to B. You could ofcourse represent other obstacles like buildings or lakes or high hills in the map in the same way.
Does anyone know if Panda has any search algorithms built in? Or can anyone point me to a good implementation of A* in Python? Ideally the search function should be implemented in C for speed though.
To get characters to follow a path a new path-following steering behaviour would be needed, but this would be easy for simple polyline paths and I think it’s already been discussed in this thread.
That would more-or-less replace the arrival steering behaviour. But for steering behaviours like pursue, evade, follow and wander it doesn’t make much sense to be following a path, so it might be necessary to add a ‘no penetration’ steering constraint to prevent characters from steering into obstacles. Or just ignore it. For wandering, you could combine path-following and wander and have characters wander along a path (you could, for example, repeatedly compute a path from A to a random quad B then wander along it, or you could use pre-defined paths to wander on).