Disabling animations.

I started optimizing my game characters and everything goes just fine,but a small problem:
How would I turn off the animations of the characters that are not in the camera frustum, and turn them back on when i they get in the camera view?
Any example?
Please help me,as its very important.


Maybe with the use of a radar sensor on the Camera you could trigger the animations of your characters to stop. The sensor would be pointing into the opposite direction 180degrees width so it can detect the objects behind the character within some range and suspend animations. I don’t know if this method would put a stress on the performance though. It may be better not to use pulse mode, so trigger only once and use a second radar sensor (also not pulse mode) in the direction of the Camera 179 degrees width to trigger the characters in front of the Camera to resume their actions. Just an idea.

Here’s an example. When it detects a character in front of the Camera it only triggers once to play the action. And when it detects a character behind the Camera it only triggers once to suspend the action. Left and Right Arrow to turn.


Detect01.blend (83.2 KB)

Its a great example,but if for simple cubes there is a considerable physics usage,more sophisticated objects,and a map would slow down.
Thats a good aproach though.

yes , radar is wasting i tried with 100 cubes : physic to 5.0 ms !!!

the best choose in my opinion is pointInsideFrustum()
for some reason is fast alsmost as getDistanceTo()

try this, put it on all enemy ,with always true:

import bge

def m(cont):
    own = cont.owner
    if not "init" in own:
        own["init"] = 1
        own["oldFrame"] = 0.0
        own["LOD"] = 1
        own.playAction("ArmatureAction",11.0, 80.0, blendin=10, play_mode=1)
    cam = bge.logic.getCurrentScene().active_camera
    if cam.pointInsideFrustum(own.position) :
        if own["LOD"] == 0 :
            own["LOD"] = 1
            own.playAction("ArmatureAction",11.0, 80.0, blendin=0, play_mode=1)
        if own["LOD"] == 1 :
            own["LOD"] = 0
            own["oldFrame"] = own.getActionFrame()

i can get until 950 “chars” (5 bone)

Like MarcoIT posted in his example above, cam.pointInsideFrustum() and armature.stopAction() should be able to do this. There’s also sphereInsideFrustum() and boxInsideFrustum(). This way, you can check to see if an object is partially onscreen:

in = cam.sphereInsideFrustum(obj.worldPosition, 2) # worldposition is the center of the sphere, and 2 is the radius of the sphere

 if in == cam.INSIDE or in == cam.INTERSECT:
     # play animation
       obj.playAction(arguments) # replace arguments with the actual arguments of the function that you need
     # stop animation

Thanks guys! Really good examples! However, I ve passed this task to agoose77 as he is now my main coder,and he will be doing LOD ,and will code the characters.

Thanks MarcoIT and SolarLune for making us aware of these camera functions!

Hello everyone, I tried to tie scripts to the armature, but thDetect01_frustum_MY.blend (102.5 KB)
e animation continues to play even if the camera turns away.

I would love to learn how to do like that in blender to? Please Help me, advise me please.