Parenting a cube to an empty disables collisions

I’m working on a small game prototype in blender, I just want to see if it would be a good idea for a game. What I have is an empty following a path. The character is parented to the empty as is the camera. I also have another cube that follows the empty to serve as a cage for the character, so he can’t run out of camera view. The problem is that everything I parent to the empty, the collisions are either disabled or the object goes crazy at start and glitches out of view.

Here is the blend.

Attachments

proto.blend (506 KB)

import bge

cont = bge.logic.getCurrentController 

own = cont.owner 


#if target is a name, use it to look up the object
if type(own['Target']) == str:
    own['Target'] = own.scene.objects[own['Target']] 

own.worldPosition = own['Target'].worldPosition 
own.worldOrientation = own['Target'].worldOrientation 

own.localLinearVelocity *= 0

This code, is to be ran by the cube

The Cube must have a property, ‘Target’ in it, set to string (the name of the empty)

(instead of parent, we just move the cube and rotate it each frame)

That didn’t seem to work, still won’t detect collisions and if i unparent the cube from the empty with your script on the cube the cube just stands there or falls to the ground.

Always[true pulse mode] ---------[python]

In cube barrier?

Also, to make a barrier this way is tricky, you need a few box colliders offset from a point, or use a compound shape hack etc.

If I get a minute I will make a demo.

But basically

Point = empty.worldPosition + (empty.worldOrientation * Vector([X,Y,Z]) )
That is unique to 6 objects
And you have to orient each cube as well.
rot = emptyObject.worldOrientation.to_euler()
rot *=Vector([X, Y, Z])
#x y z in this case are radians

Yeah I don’t understand that stuff, I’ve got everything working as it should except the collisions. The character moves around, the camera tracks the empty along the path, just needs the character to not go through objects or to be able to move out of camera view. Maybe you can do it some other way.

Maybe you could have only the camera track the empty and then have the whole map animate to give the illusion of the character moving. I’m gonna try and see if that works.

EDIT: It sort of works but not really, as the map moves towards you the empty is animated only on one axis to zig zag through the map as it’s coming towards you. The cube stands still but when the cube hits a wall it quickly disappears out of view of the camera the camera also moves quickly down the path, much quicker than it would be reasonable for the character to move.

Also I think ideally the character should be at the center of the camera at all times, hmm tricky. If only there was some way to have the character detect collisions and remain within the camera’s view.

Ok I looked over this gameplay idea once more and managed to improve on a couple of things. Instead of parenting the character and camera to an empty I parented the character to the camera and animated the camera through the scene. The camera sets the speed of the character and the rotation the character faces, so now you’ll slide smoother through the scene. But still you can’t enable collisions for the character, I tried to parent some objects around the character and while they won’t bug out they seem to adopt the collisions of the character. Something around the character needs to detect it’s collisons so he can be hurt and not walk through walls.

My question is, is this a limitation of the game engine or is it something most game engines have in common, that something that is parented to something else, it adops whatever collisons that thing has. Because if it’s just a blender game engine thing it won’t matter since this game would probably be made in unity or unreal. This is just a concept really.