3rd Person Issues & 1 Tip: Divide big walls into pieces

I got a request and a GIFT to share this time.

UPDATE: I find that sticking Invisible Occluder Blocks right behind the camera helps partially solve this issue. The game still seems to hate having to render characters partially if parts go “offscreen”. But there’s no frame drop.

Request: Is there a way to prevent characters from appearing into view until they are fully past the camera’s Global Z axis? Having NPCs and Enemies standing both behind and in front of where the camera is slows down the frame rate a lot.

Speaking of this issue, subdividing a big wall and splitting the polygons into separate meshes will prevent the game from dropping its framerate. But a one piece big solid wall will slow down the frame rate a lot if that wall starts going towards and past the camera.

is this the thing where the mesh is getting deformed outside of the bounds? without a blend we will never know.

" Is there a way to prevent characters from appearing into view until they are fully past the camera’s Global Z axis?"

this essentially translate too “my charactar is to close to the camera how can i prevent them from being rendered when to close to the camera?”

and yeah you can do that!

distance = ((x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2)1/2

and if distance is < whateverdistanceyouwant

you can either use the bge to hide the object or set transparency and specularity to 0

but i’m pre sure you can’t just use a ton of logic bricks, you need python.

import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
obj = cont.owner

scene = GameLogic.getCurrentScene()

distance = ((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2)**0.5#please don't use "1/2" that's just silly. uses extra unnecessary processing power.  
if distance < 1:
#honestly I forgot how to do these two things, but it is definitely possible as I have done them in the past. so you'll have to figure out that on your own.

sorry I can’t remember the commands for those two last bits, it’s just not in my memory. wish i could be more help, but yeah, it’s possible.

1 Like

one word… mathutils

itll change your life.

vec = targ.worldPosition - char.worldPosition
dist = vec.length

python is SLOW!! dont use it unless its really needed. bge has a lod system based on compiled code, use that.

but any way, this hides things.
obj.setVisible(state, True) #args (visible, recursive)

1 Like

i don’t see how adding more overhead could possibly be a better solution than literally doing an equation.


its cleaner and easier to read. theres a chance its faster as well, someone who knows the nitty gritty might be able say.

by default, all worldPositions are mathutils.Vector, and theres whole lot even more fancy things that come with it out of the box.

1 Like

should this not be enough

distance = camobj.getDistanceTo(obj)

a function that is build in, is the fastest way.

1 Like

distance = sqrt((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2))
length = sqrt((x*x) + (y*y) + (z*z))

Either way it’s vector substraction, square each element and square root of the sum.

You could also numpy.linalg.norm(a-b) if you fancy, there really isn’t a difference between that, mathutils and a builtin that’s also written in c. Not that a human brain could notice either way.

But piece of advice, if you’re going to do vector math on every object on every frame, don’t do it in python. That’s what all these c libraries are for.

1 Like

I am working on a few models with animations that I am willing to give away for free before releasing the actual game. So I can share blends before posting more questions.

Just wanted to say THANKS everyone for the suggestions though! :slight_smile: I will post again when I can post blends with my issues.

1 Like

Doing dumb things like looping through all your objects every frame is slow. Python is plenty fast enough for everything you’ll ever want to do with it. If Python is your bottleneck then you’re doing something poorly.


I could be wrong, but the way I circumvent this issue is by simply adjusting the clipping distance for the active camera in the properties tab. You can set both near and far clipping limits, so that objects that are super close to the camera will disappear (as well as far away)