Platform Physics

I want my character to be able to move through the platform from the bottom and side, but not from the top.

in platform properties
Platform = a tag for identification
Physics = A string, the name of a physics object on a hidden layer
PhysicsHeight = float , the height of physics object

in player

Near(property Platform)----------python

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()
Near = cont.sensors['Near']

if Near.positive:
    for objects in Near.hitObjectList:
        if own.worldPosition.z>(objects.worldPosition+((actor height/2)+(objects['PhysicsHeight'])/2)):
            objects.addObject(objects['Physics'],objects,1)

so if you are near a platform, and you are above the platform add in a physics object for 1 frame.

this way while your standing on the platform it has physics,
and it disapears otherwise.

you can also later have if down key held, dont add physics
(down jump)

I tried something, but couldn’t get it working.

Here’s the blend file if you want to give it a shot.

Attachments

game_test.blend (717 KB)

Check it

the near sensor needed to be in the player.

this way you can use 1 sensor , platforms should be no wider than just under near diameter, (near radius *2)

Attachments

game_test_BprReturn.blend (663 KB)

Thanks, it works!

No problem, happy blending,

Just mark this thread as solved, in advanced edit of first post,
change prefix to solved.

=D

Jump Down

Attachments

game_test_BprReturn2.blend (663 KB)

Now I’m just mad because the solution was so simple. :frowning:
Thanks, though.

Don’t beat yourself up, I do this alot :slight_smile:

I have been trying to write efficient code using the bge for a long time.