Point of collision coordinates

Hi all,

I’m having great success learning Python with the BGE as my first language. The learning process has been really enlightening. I’m currently just struggling to get my head round one thing:

Scenario:
I only want my character to be able to jump when it’s colliding with another object below it.

Approach
Get the coordinates of the character. Get the coordinates of the collision. If the collision is below the character then enable jump.

Problem
There doesn’t seem to be a way of obtaining collision coordinates.

Alternative approaches that nearly work:

  • Obtaining the character coordinates and the collided object coordinates. If the player is above the collided object then enable jump. This gets the collided object coordinates from the object origin, so any terrain that isn’t flat doesn’t work.

  • Using rays I was able to use an axis for collision detection. This worked very well, though the only problem is it was detected on a one dimensional line from the center. So if the character was slightly over a ledge with the center over as well, there wasn’t a collision.

  • Applying a material to the top of all collideable terrain and using material rather than property collision detection. This would work, but it’s too clunky and not flexible enough.

Any help would be great!

I think you’re saying that you only want your character to be able to jump if its touching an object (like the floor). There’s a million ways of doing it with python. Often the simplest way is with a Touch sensor. Or if you have multiple objects you want to be able to jump from, multiple Touch sensors attached to an OR controller.

Thanks for the reply!

Actually I only want to be able to jump when what I’m colliding with is underneath me (to avoid being able to jump from the side edges of platforms or be able to infinitely jump when I jump and collide with the underneath of a platform).

Here’s an untested sample that calculates if the object you’re colliding with is underneath the player. However the coordinates are obtained from the object origin, not the collision, which isn’t much use.

fx,fy,fz = floorTouch.hitObject.position
px,py,pz = owner.position

if floorTouch.positive and fz >= pz:
print "underneath collision occuring"

Any ideas?

If you are not yet that familiar with python I still might recommend touch sensors. You can apply a different material to surfaces of a platform so that your player can only jump if it’s touching the right material. It can even be the same material visually but a copy with a different name.

Also I think there are better exercises with which to learn more python such as using timers and counters with the gamepad.