Raycast doesn't work

so iam making a horror game using upbge 3.0 and i wanted to make the monster detect me using raycast but it works for the first 5 or 6 seconds then it stops working although the red line still appears using the visualize option anyone know how to fix this problem?

Hello and welcome to BlenderArtists.

Your problem:

  • Could be as simple as increasing the check Distance of your raycast node.
  • Or it may be that your player’s mesh is occasionally blocking your camera’s view.

hi rayCast using for check only - visible player or actor or not visible for unit, walls, boxes, barrels cut visible line, if player detect you need on logic track to detect target - somebody steering actuators - im use python for detect player
own = cont.owner
scene = bge.logic.getCurrentScene()
active_cam = scene.active_camera
steering = cont.actuators[‘Steering’]

dist = own.getDistanceTo(active_cam)
if dist<=3.000:
start = own.worldPosition
end = active_cam.worldPosition
ray = own.rayCast(end, start, 0, “player”)
hit = ray[0]
if hit:
if ‘player’ in hit:
steering.target = scene.objects[hit.name]
this simply logic for detect player and tracking to player, for raycast working you need assign tap work in sensor and assign impuls mode for sensor