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?
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.
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
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.
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
controller.activate(mainGame)
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
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.
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”.
No. As far as I can tell the Character Physics type is not a true dynamic object, so it is unaffected by servo controls
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.
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.
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.
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.