AI: Detect close player


In short, I want to know how my enemy spacecraft can detect my player spacecraft. In my game, the enemy spacecraft is rotating around a planet clockwise and my player is rotating counter-clockwise. What I want is that when the enemy spacecraft is starting to “see” the player spacecraft, he will slow down his speed and start attacking.

I think there is a method to know the distance between 2 model but I can’t find it in the documentation.

Also, my 2 models (the enemy and the player) are on completely different root node on the scene graph and I’m not sure if this method of distance is relative or absolute.

Can anyone help me?



well to get the distance… thats sorta easy

distance = spaceship.getPos(enemyspaceship).length()

if thats not enough and if you want to check if the spaceshipt is really in the line-of-sight.
you’d have to cast a collision-segment with the endpoints at the ships positions. if no collisions with other geometry appear they are in plain sight.

There’s also NodePath.getDistance(other NodePath).

Thanks a lot!

I think all of this is going to help me a lot!


wah that really helpful

so long I always using incredible huge sphere colision to detect any even
thank for share