Negating upward momentum when hitting a ceiling, with character physics?

So I’ve got an object set to use character physics, and everything’s going pretty alright. Right now, I’m trying to get it so the object stops trying to ascend when it jumps via a motion-actuator set to “Character Motion” and flagged as “Jump”.

I can set a sensor for overhead collisions, but I don’t know what to do from there. How can I control character motion from a script? Is there a way to manipulate jump-force from an actuator?

Clarification: do you already have a working jump for the character, and this is just for the special case of hitting a ceiling? If so, why don’t you have the sensor trigger whatever change causes the character to descend normally?

I don’t know how to do that. The motion actuator applies a jump-force, and I don’t know how to control that. :stuck_out_tongue:


character.blend (584 KB)

Found the problem! It turns out it wasn’t the actuator, it was your collision mesh.

For some reason the “sphere” collision bounds weren’t working right. Instead of stopping when they hit a static object, they passed through the mesh a bit. When it tried to fall, this overlap slowed it down. Almost as if the static object was made of honey instead of steel.

If you change the collision bounds to “Convex Hull” it should work just fine.

Huh! That’s weird. Let me try that out. …

Gah~! That’s one problem solved that introduces another~!

I was using the sphere-setting for bounds because it’s the only one that doesn’t slide down any and all inclines. I just can’t get the hang of character physics, yo. :S

Programming in a nutshell :slight_smile:

Apparently the character physics sliding-thing is a problem with the Bullet engine using constant force on a character object. There may be some clever workaround with Python and applying an opposite force, but it also might be simpler to go back to “Rigid Body/Dynamic” until the next update fixes it. Good Luck.

I found a solution!

To stop an object with “Character Physics” from sliding down a slope or incline in the bge you need to change the “Max Fall Speed” to 0 when it is touching said incline. To do this:

1. Make all your inclines separate objects with a “slope” property

For this to work we need to be able to detect when the object is touching an incline. The easiest was to do this is to make the slope a separate object.

2. In an “Initial” state for you character, save the current “Fall Speed Max”

We need to save that fall speed for later. First we get the speed using a “constraints” wrapper,
then we create a new property on our object called “Gravity” to store it in.

import bge

controller = bge.logic.getCurrentController()

# This actuator changes the state once 
# we are done initializing the object. If you
# have your own initialization code, you can
# ignore this line and the last one.
mainGame = controller.actuators["Main_Game"]

owner = controller.owner

wrapper = bge.constraints.getCharacter(owner)

owner["Gravity"] = wrapper.gravity


3. In a different state, create a collision sensor

Make sure that it only reacts to objects with the property “slope”

4. Attach the collision sensor to a python controller

The next part is straightforward. If we are touching the slope, the “gravity” is 0. If we are no longer touching it, we set the gravity back to its original value

import bge

controller = bge.logic.getCurrentController()
slope = controller.sensors["Slope"]
owner = controller.owner

wrapper = bge.constraints.getCharacter(owner)

if slope.positive:
    wrapper.gravity = 0
    wrapper.gravity = owner["Gravity"]

I’ve attached a simple sample file (“StopSlope.blend”) and a modified version of your original file (“character.blend”). Press left and right to move the cube in my file. Spacebar to jump.


check this out


supersimpleNegateMomentum.blend (425 KB)

Thanks for posting the file but, I must apologize, what idea are you trying to show me?

The cube is still inching down the slope, and when I press a key it just falls down faster. That and the cube is set to “dynamic” instead of “character”.

I have never found reason, at all to use the character settings,

but anywho,

Setting the linV does not appear to apply to charecters?

What is the point of the character setting?

To use python and not physics?

LinV = 0,0,0 + force(0,0,9.8*mass) = stopped

  1. No. As far as I can tell the Character Physics type is not a true dynamic object, so it is unaffected by servo controls

  2. The main reason is to simplify things. For making simple games, especially for beginners, character physics make things like jumping and stepping over small obstacles easier to implement.

  3. Character objects still use physics, but I will admit they are geared more towards setting up your own controls in python.

That last line doesn’t work because, as I said, you can’t set linearV on a Character Object.

Character physics works best for moving along varied ground, in a way that dynamic objects can’t do as reliably. I’ve come close, but I can never get the level of precision and consistency that character physics can provide.

So if it can’t have LinV then how does it have upward momentum in the first place?

A property or variable? you can always use a separate property on the underside of objects, on a collision object, that when collided with by the head while in the jump action modify that element.

Collision property “Underside”-------------python

It jumps via jump(), a method exclusive to character objects. Looking into the source code, I’ve found a variable tracking the object’s vertical velocity; but there’s no way to access it via Python.

Want to use my rig :smiley:

What type of game are you making?

I could just write a logic based rig with python handles, or a pure logic solution,

I look at the character settings etc, and feel I have more power over motion control physics and a few scripts that I have laying around.

I’m making a fighting-game with movement very similar to Super Smash Brothers. If you’ve got a working rig you’re willing to share, I’d be more than happy to try it out. :slight_smile:

Ok, I use a property to control the animation state,

I’ll set you up with a way to trigger any animation and any physics force applications,

Note the Mesh Cube.

it has the logic to trigger 1 animation

this logic can be re-used to trigger any animation and any force applications,

Note how the physics object “Empty” is copying the animation property to apply forces?

If you need me to rig your first couple actions so you can get a nice cross section of how to do it just let know,


3rd_person_cam_beta (1).blend (469 KB)

here is a remake of the rig, I added back up as another action,

you can use a 6dof link and only lock 1 axis, this will make it so the rig is confined to a 2d plane as well :smiley:

I also dumped all the camera rig ,


ReRigForAlphons.blend (473 KB)

This has jump, jump forward, walk and back up, lost my internet so I had to send via my phone.


ReRigForAlphonsB.blend (480 KB)