I’ve got objects, some near the player, some far away.
When starting game, all objects being calculated ( game slows down ), not just the ones nearby.
How can I just let calculated the objects nearby, most likely without giving every object a near sensor to look for the near player to show themselves.
Or another alternative.
In game there’s a range sight, all behind it isn’t visible, you see the background.
Is there a way to show object behind this point/increase the range, without hanging them onto the player/making everything smaller?
you havent specified what you want to know.
what sensor are you using.
what do you mean calculated
range sight? - do you mean the distance limit that you can see?
You could look into dynamic loading to do some kind of LoD system. In this case the levels of detail would simply be full and nothing. At this moment I am not certain how I would proceed with an LoD system, my first instinct is to use empties . . .
With empties you can’t use replaceMesh, so they are quite useless… In this case you should attach a python script that activates only when your player/camera moves(there’s no reason to update the status if nothing changes) and use visiblility flag.
Something like
if condition:
if bge.logic.getCurrentController().owner.getDistanceTo(bge.logic.getCurrentScene()["Your Player"]) > the_distance_you_whant:
bge.logic.getCurrentController().owner.visible(0)
else:
bge.logic.getCurrentController().owner.visible(1)
In addition you may also want to disable the phisic for this objects. It’s the easiest and fastest way
Here’s what he put in an easier to read smaller fashion (didnt see he’d posted it)
import bge
controller = bge.logic.getCurrentController()
owner = controller.owner
#set the name of the player object here
playername = ""
#sets the playerobject
player = GameLogic.getCurrentScene().objects[playername]
distance = owner.getDistanceTo(player)
#toggle distance
toggledist = #yourvarhere
if distance > toggledist:
owner.visible(0)
else:
owner.visible(1)
I’m trying to use the script in a demo scene, but I get an Error:
TypeError: ‘bool’ object is not callable
Line 25 / Line 27 ( owner.visible(0) / owner.visible(1) )
I’m using 2.49… possible that I have to call visibility in another way?
import GameLogic as Gl
#import bge
controller = Gl.getCurrentController()
owner = controller.owner
#set the name of the player object here
playername = "OBplaer"
#sets the playerobject
player = Gl.getCurrentScene().objects[playername]
distance = owner.getDistanceTo(player)
#toggle distance
toggledist = 10
if distance > toggledist:
owner.visible(0)
else:
owner.visible(1)
Be careful with setting objects visible and invisible.
If you have a large open world this method is useless because the physics are still there even if the objects are invisible so the fps will drop sooner or later.
controller = GameLogic.getCurrentController()
owner = controller.owner
#set the name of the player object here
playername = ""
#sets the playerobject
player = GameLogic.getCurrentScene().objects[playername]
distance = owner.getDistanceTo(player)
#toggle distance
toggledist = #yourvarhere
if distance > toggledist:
owner.visible = False
else:
owner.visible = True
Ok, visible/invisible is working now.
Not fully tested in the whole scene, cause i want to try add/end first.
If I wanna add an object I need something to say where it should start.
Meaning if I end an object, it is gone, so has no position anymore where to add again, right?
I think is more easy to enable/disable phisics. Adding object is far more difficult(since you can’t use getDistanceTo for adding them): you should have a dictionary where all the objects are listed with the coordinates in which they should be, and then with a “for” you should control the distance of each object… Not the best thing for performances.
Try http://www.blender.org/documentation/blender_python_api_2_55_0/bge.types.html#bge.types.KX_GameObject.suspendDynamics
and the function below it
(i think her’s something similar for 2.49)
ps: if you’re starting a quite new project, i think you should really go with 2.5. It’s quite stable now(i don’t get crash except when i try dynamic loading[it doesn’t even exist in 2.49]), and has a far better api.
@hundi:
Why do you need to calculate the distances between the objects?
The clipping distance can be set at the camera’s edit panel. Be carefull with that. It influences accuracy of the Z-Buffer.
I suggest to check wikipedia for: Camera Frustum and Z-Buffer.
Clipping start/end is what I search, to have a greater vision range.
The distance is needed, because object should only be displayed/used/etc when player is coming in range.
Even if objects aren’t visible for the cam ( Clipping distance ), they still slowing down the game.
And now I will check Wiki^^
P.S.:
Is there somewhere a table with old and new python like ( old => setDRot(x,y,z) and new => DRot = [x,y,z] ) on the internet?
In that case, LOD is the way to go. Additionally you can try remove/add objects disable/enable physics and animations as part of the LOD.
It is quite complex, but you got some hints already.
The 2.49 APIalready contains the new API changes. It does not contain syntax changes from Python 2.6 to Python 3.
With Blender 2.5x there might be additional changes to the API. I think the API is still backward compatible to 2.49 without the deprecated parts.
Well I will see for physics and add/remove first, cause I need some python parts for it.
I’m still searching for one thing:
The above script has to be used on every object.
Cause I’m more like a beginner in python I could use a hint how to realize it, so that only the player has the script.
Something like a script that lists the objects nearby, get a property of them ( which says what obj it is ) and setting mesh and physics to this objects.
Think it should be faster, right?
Edit:
I’ve tested a bit and I set the objects invisible, suspended the dynamics, replaced the mesh and physics with a plane without physics and set the objects inactive at all time.
And I can’t see the game is running faster.
Just completely end all these objects lets the game running faster again.
Did I forgot to delete/replace/disable something which slows game down?
Edit 2:
I got an inspiration after posting^^
The Logics I build in for Lod and Co were slowing down the game as much as without Lod and the therefor used Logics.
Will look for how to tight up the rasterizer now.