near sensor on dynamic objects.

sorry, wrong forum .
Are we allowed to use the near sensor on moving meshes? I am reading some older posts about it being either broken, or it cannot be used on a rigid body or dynamic object.

I want to use it on my player object to turn on and off emitters, and to toggle visibility of some of my denser meshes.

rule number one of the BGE:!!.png

Experiment with it, you might discover awesome stuff.

While cyborg_ar has a good point, it might sometimes be useful to know how something works if you are trying to figure out if you’re messing something up.

Unfortunately, I can’t provide a clear answer, but I think you should be able to. If all else fails, use Python :smiley:

Well thanks anyway guys.
I am not going to risk ruining all my work to test something that might be faulty .
I have already lost a bunch of work and time on the shape key system.If I would have just asked a few days ago someone might have warned me that not all of the shape keys features actually work in the game engine.
The reason I asked is that I do not see any adverse effects in my small test file, and i do not see any console messages.After a bit if searching in this forum, all I find is mixed messages.The Wiki never mentioned the rigid bodies or the dynamic objects. I am worried that the bug might not give any indications of when you add too many models or textures. It never warns you anything, but your FPS goes in the gutter.

I was able to ask the same question at Bzoo, and I was able to get an answer, plus a link to a pretty sweet work around script snippet that I can learn from!
Ha! and I thought I would never use what I learned in my 9th grade french speaking class.
Bonne journée !

The last time I used a near sensor was for a coin collect, and it worked with a dynamic character. However, as I think you were mentioning, the near sensor can really chew up your framerate. And I’m not sure what script you are mentioning, but I’m going to guess it involves getObjectList() and getDistance(). :wink:

Thank you Moguri. I will try the near sensor and the script , then I will let you guys know which works better.

It is not really a big deal. I just want the smoke to come out of my house chimney. and to toggle my waterfall on and off only when the player is near it. i might have some of the house meshes cull too, and see if it gains me anything.I really want to bring some motion and life into my game without too much CPU loss.

As long has you don’t have too many near sensors, you probably won’t have much of an issue with frame rates. I had about 40+ sensors and it ate up about 10~15 fps.

The near sensor can be used on dynamic object without any problem.

The near sensor has nice filter features that reduces largely the CPU they consume: they are only sensitive to objects with Actor flag enabled and if you set the Property field, they will detect the object having the giving property.
The near sensor only computes collision data for the objects that pass these filters. If you set them right, they will consume little CPU.
For the specific use that you’re mentioning (scene object detecting the proximity of the player), only the player object should pass the filter, so the result should be very good. It can actually be better than using getDistanceTo because the bullet library has an efficient broad phase filtering on the AaBb box intersection that disables all calculations for the sensors that are far away.

Otherwise I have in mind to implement a nice option: instead of full collision data, only check if the center of the object is within distance. This simplified algorithm will consume almost no CPU and still benefit from the AaBb filtering. I just need to see if I can tweak bullet to do that.

Ben, back when I was working on this coin collect (it was either 2.45 or 2.46) I had 40~ish coin objects each with a near sensor looking for the player. And while the effect wasn’t devastating, there was a noticeable drop in frame rate. Noticeable enough that the game play got smoother as the player collected more of the coins :spin:

Thank you ben2610!
I feel safe using them now!

I also feel a little bit silly. I have every static mesh in my map set with the actor flag on. The good news is that I can optimize it even more tonight without much effort!!

Thanks also for the new “state system” you made. i am going to use it very heavy in this game!