I would like to know how it is possible to create a radar type sensor with only python in bge.
To specify, he would have to fire at the Y + position up to a distance of 100 meters, starting from the cube.
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
Basically you measure the faces an imaginary line is crossing through.
The mesh of the game object you measure with will be ignored (you want to find another object, rather than itself).
Here is a short demo measuring between [0,-10,0] and [0,10,0]. The coordinates are given in scene space (world coordinates). The direction of the measurement matters as the nearest face to the start point gets returned. The endPosition is a reference where to point to. The measurement will stop after reaching the distance of 15 (regardless the distance to the endPoint).
import bge controller = bge.logic.getCurrentController() owner = controller.owner startPosition = [0,-10,0] endPosition = [0,10,0] distance = 15 hitObject, hitPosition, hitNormal = owner.rayCast(endPosition, startPosition, distance) if hitObject: print("Object hit:", hitObject, "at", hitPosition, "the normal at that point is", hitNormal) else: print("hit nothing")
Be aware this is a one-shot. This means you need to call it each time you need to measure. The python solution fits when you need to measure:
When you just want to "reinvent" the ray sensor, notice it is way easier to use the ray sensor.