hi guys, thanks in advance for any and all help.
I’m trying to make an enemy wander around randomly, while staying in the play area, not running into walls, not walking off ledges (except in certain instances), and not run into obstacles.
to do this I figure firstly, that I’ll want to use the nav mesh for both navigating to the enemies selected destination, but also checking to make sure that destination is within the play area.
my steps for doing this are to 1: get the enemies coordinates,
2: generate a random number within a preset range to either add or subtract from the enemies x (and another for y) coordinates, and shift the z coordinate up a bit,
3: save the new coordinates to then use as the origin for a ray_cast (this is as far as I’ve gotten),
4: ray_cast down form the origin to the nav mesh, (or a set distance to avoid the ledge issue)
5: if the ray_cast hits the nav mesh, spawn an empty at the hit location, (if not, restart loop at generating a new set of coordinates, this ensures target location is in the play area)
6: ray_cast from enemy location (shifted up slightly to start from enemies eye-level) to the new empty,
7: if the ray_cast from enemy to empty hits nothing between them, set empty as target, (if not, restart)
8: feed target to steering actuator and activate it. (creating a path to fallow from enemy to target that avoids walls, objects, and leaving play area.)
this should be totally doable right? the problem is that I’m not sure how exactly to use the ray_cast function. I’ve been searching around the wiki, here, and google for info on it and have found alot of different info but I’m still not entirely sure how to use it.
for 1: how exactly do I make the ray_cast point down? (0,0,-1) for direction?
2: I’ve read somewhere (but can’t find it again) that there is a parameter for ray_cast that can take the name of a property, and that ray_cast can return weather or not it hit an object with that property. is this true? and which ray_cast function does this? (I ask this because I would have multiple areas each with their own nav meshes, so I can’t just do ‘1st hit == nav mesh name’)
3: just about everything I’ve found about ray_cast says something about local vs global space and I’m not sure how exactly that affects what I’m trying to do. if I’m trying to set the ray_cast origin as an offset of the enemies location, would the coordinates returned for the enemy be global? and if so then the origin would be global as well, but then the coordinates returned for where it hit the nav mesh would be in the nav meshes local space and needs to be converted to global before I can set and empty there right?
if I think of more questions (because I think I had more) I’ll add them in. thanks again for any and all advice and guidance you guys can provide :).