how to check if the player is on ground....e.g. 'onGround == True'

class bge.types.KX_CharacterWrapper(PyObjectPlus)
A wrapper to expose character physics options.
onGroundWhether or not the character is on the ground. (read-only)
[TABLE=“class: docutils field-list”]
[TR=“class: field-odd field”]
[TH=“class: field-name”]Type :[/TH]
boolean

[/TR]
[/TABLE]
I have no idea how to read the api documentation…I just don’t get it sorry… I see
‘bge.types.KX_CharacterWrapper(PyObjectPlus)’ and I assume it is
bge.types.KX_CharacterWrapper(‘expecting something here’)

if own.bge.types…blah blah:).onGround == True: …nope…

you get the idea…I have NO idea :slight_smile:

so how do I use this…I mean I can just rayCast, but this is built in a probably faster than yet another rayCast.

The easiest way seems to be using collision sensor and test for the “ground” property or you might use collision callback and test the alignment of the z axis against the normal

I like to shoot a ray downwards

lol…in the first case it is the child object of a collider…it is a rig(armatures)…
and in the second case many rayCasts slow the engine…but in the end it is what I did…to be more clear I did use a rayCast…I would rather not though.

Then use a cube, place it below player, compound collisions, and put a collision sensor on it.

I like to work with a cube, a ray check just checks the center so standing on an edge can get you stuck.
Or you need to cast multiple rays from every corner a cube is nice and simple and does really well.

The API documentation tells you the inheritance tree.

KX_CharacterWrapper(PyObjectPlus) tells you that KX_CharacterWrapper is a subclass of PyObjectPlus. In python syntax:


class KX_CharacterWrapper(PyObjectPlus):
    ...

In other words:

  • KX_CharacterWrapper inherits all attributes (variables and methods) from PyObjectPlus.

Hint: Have a look at PyObjectPlus what it inherits.

I guess this is irrelevant for your title question.

The important information is:

  • KX_CharacterWrapper is not a KX_GameObject!

It gets implicitly created and applied when you change the game object’s physics type to “Character”.

You can get the character wrapper via bge.constraints. The documentation does not mentioned that, I had to find that out via internet search).

KX_CharacterWrapper.onGround

usage:

run this code on a controller of your character object (= physics type Character)


import bge

owner = bge.logic.getCurrentController().owner
character = bge.constraints.getCharacter(owner)

if character.onGround:
    print("The character is on the ground")
else:
    print("The character is in space")

OMG. I actually feel bad everytime I cannot figure something out for myself. I am however very thankful(vielen dank Monster…du kanst der engine sehr gut…my german is horrible :slight_smile: )

and I would have never figured this out…
character = bge.constraints.getCharacter(owner)

I did understand I needed to access the physics controller…just no idea how…I thought it would be part of the owner
I would have needed to know to look in constraints first as well…sometimes you need to know the answer before you can ask
the question…

I was trying to find the link to pyObjectPlus…and it is very relevant…the more I can help myself the better.