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:
Each hotspot object has a sorrounding plane with a property.
An empty is parented to the player and has a lot of Near sensors connected to a Python script, waiting for the properties.
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, 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
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).
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.