Optimizing near sensors

I´m building a scene which requires some text to appear when the user passes by. Right now it´s coded with near sensors, even thou I prefer the ray sensors, but had some trouble with them. Anyway, I need to improve the performance for any of them.

The scene is big and needs to have some 100 hotspots*. * If that´s not possible, I can cut down that number of spots…

The way I´m doing it right now:

  1. Each hotspot object has a sorrounding plane with a property.
  2. An empty is parented to the player and has a lot of Near sensors connected to a Python script, waiting for the properties.
  3. The Python code checks which sensor triggered it and feeds the right text into the text object.

Is there any way to sptimize this, to lessen the burden on the Physics, which is starting to bottleneck?

Would a setup with ray sensor (s) and “get object hit” help in performance?

And is there a way to get rid of the many logic brick connections at step 2? Maybe a dictonary with all the objects or sensors … ? Would that speed up the game play, besides the construction time?

so… the near sensors only detect the player?

why not use a near sensor on the player then, and some python to change a property on those objects?

then you have only one near sensor…

No, actually the player empty has many near sensors and they sense the proximity of the objects with their properties. Each sensor waits for a specific object property.

Great idea, to have just one sensor on the player, but I´m afraid I didn’t fully grasp the concept. How would I do this? How the player near sensor would know what object is near?

so, you say you are detecting objects by property eh?

in python you can check if an object has a particular property with the hasattr method

for example [in the python console thingy]

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> hasattr(math,"sin")

so you want to get the near sensor, get the objects it senses, and check if they have particular properties…

Yes, I’m detecting them by property. I think not by the best way… I have one near sensor for each of the hotspot objects, all linked to the same python script that checks wich one was sensed.
So, with this technique you described, I can setup the scene with one near sensor with the player and get the objects it senses only with Python?
Or I still need the various logic brick connections? for each object that can be sensed?

Isn’t there a way to use raysensors for near in a cirkel range? Like you have an empty with a specifique axis in a direction, set ray sensor on that axis, and spin the empty around like a radar but very quick. Now try if it detects a object.

I used raysensors a lot, they even beat the collision sensor on shooting bullet and place a hole on the wall, and end the bullet object, while collision sensors sometimes fly trough everything. The hardest part is finding the balance between the speed and the range of the ray sensor. :-?

I guess I could use a Ray sensor, even without the rotation trick, as I only need to sense the objects in front of the player.
My doubt is how to setup the logic bricks with just one sensor and Python. How should I set up the sensor to be able to sense ANY object (to refine later in Python).

No, all you need is 1 near sensor.

Then, step-by-step:
give all hotspots a “hotspot” property
have the near sensor check for that property
link the near sensor to a python script.
the python script uses hasattr() to check whether or not the sensed object has a certain property.
You can then have the python script do whatever action you want as a consequence of being near that object.

Now, guys (z3r0 d, JD-multi and lemmy), thanks a lot ! We got it working right and my game’s performance sure thanks!

Each object has 2 properties, one generic, for the only near sensor and other for the Python script to know what object triggered it.

Here’s the code:

import GameLogic
g = GameLogic
c = g.getCurrentController()
o = c.getOwner()

NearTexto = c.getSensor("NearTexto")
Objeto = NearTexto.getHitObjectList()

if NearTexto.isPositive():
	Line = g.getCurrentScene().getObjectList()["OBLine"]
	Line1 = g.getCurrentScene().getObjectList()["OBLine1"]
	Line2 = g.getCurrentScene().getObjectList()["OBLine2"]
	Line3 = g.getCurrentScene().getObjectList()["OBLine3"]
	if hasattr(Objeto[0],"NearCatedral"):
		Line.Text  = GameLogic.Texto[0][:-1]
		Line1.Text = GameLogic.Texto[1][:-1]
		Line2.Text = GameLogic.Texto[2][:-1]
		Line3.Text = GameLogic.Texto[3][:-1]

	elif hasattr(Objeto[0],"NearCongresso"):
		Line.Text  = GameLogic.Texto[5][:-1]
		Line1.Text = GameLogic.Texto[6][:-1]
		Line2.Text = GameLogic.Texto[7][:-1]
		Line3.Text = GameLogic.Texto[8][:-1]