BetterCharacterControl in the works

Is the “rotating only rotates the spatial” a feature that is wanted? My current implementation can rotate the physical body just fine (and the spatial follows automatically). Is there a reason why someone would want to allow visual rotation only? I could implement that option, but would leave it out if there’s no reason to have it.

Yes it is wanted, a capsule doesn’t need to be rotated as its round. Any other physics shape could be rotated but to get generic character-like collisions you’d use something like the physics rag doll in combination with the character control (or another way to get the specific collision and exerting forces from limbs etc.).

Most importantly rotating the object by simply setting a rotation would invalidate the physics information. You’d have to set the rotation speed or apply rotational forces which both don’t work well with directly setting a “viewDirection” as its done now.

The character control is for moving the character and achieving general physics (falling etc). Boxes generally don’t make much sense for characters so the only other shape thats in question which “needs” rotation is a hull shape which in turn would have to be updated when the base shape its derived from is animated. That again doesn’t make much sense.

So if you wanted a completely animated character that collides with all its limbs etc. you’d again use a (Better)CharacterControl to get the base physics (and probably have it NOT collide with other objects), and then use a PhysicsRagDoll to do the rest of the character collision and movement. That’d result in the typical FPS etc. character behavior where you can kick a box off a table but can also stick your foot into a wall when playing the kick animation (kinematic mode of the limbs), yet you can’t run through the wall (normal physics of the character control). Full body physics with full collision and animation isn’t really typical for games, some examples like UFC do it but only with two characters in the game.

Thank you for this hint. I assumed there wouldn’t be a problem, as the BetterCharacterControl uses the setPhysicsRotation method to align the body according to the gravity direction, and I more or less just copied the things that I don’t understand yet.
But using the angular velocity is probably a better way to do it. That would also make the rotation consistent with the movement. I’ll take a closer look into that.

That is correct, but aside from not needing the rotation, could it hurt if the capsule would rotate? I allow custom shapes, so I can’t assume that the shape never needs to be rotated. Now the question is do I just always rotate the shape because not rotating wouldn’t give any benefit, or do I allow spatial-only rotation because physical body rotation comes at a cost that somebody might not want to pay?

do both, add an option to enable / disable the spatial-only rotation

They’d work quite differently due to what I said. I’d suggest cconcentrating on the issues and keeping the core idea of the control instead of extending it to a point that causes new issues. (Why does my character make things explode when he turns, how can I update the collision shape when its animated etc etc)

Quick update: we suspended the “improved BetterCharacterControl”.

The reason is that we were too stupid to handle the bullet engine. The main problem is that we didn’t find a way to get between the calculation and the execution of a physics tick (the listeners are called before the calculation and after the execution), which basically prevents us from inserting custom physics.

We are currently working on a custom physics engine, which will allow us to play around with the movement profiles properly. The above mentioned features are still our goal. It just won’t have anything to do with BetterCharacterControl anymore.
I’ll make our results available for the community, once we have something that actually works. Maybe someone else will be able to find a way to make the profiles work with default jME/bullet.

2 Likes

@Denolven
I’ve only started using jMonkeyEngine recently, but I’m already hitting some of the above issues. Namely, I slide off sharp edges due to the round bottom, and I can’t jump up sharp steps because the vertical friction grabs the wall, and I bounce over the top of holes that I should fall into (due to round bottom and momentum).
Until that future world where you replace the BetterCharactorControl, is there a way for me to modify the rigid body the character controller is moving around? Like, attach a square bottom to it, or modify its friction values?

What are others doing to work around this?

  • BigScorch

Ok, I made some changes to BetterCharacterControl, which if I remember right resulted in:

-when you jump, you cannot change jump direction in mid air (you can turn in mid air, but you don’t change the direction you move in)

-you do not stick to walls if you jump into them

I seem to remember it was quite simple, but it was over a year ago. Also I don’t know if this had any other consequences. If this sounds like the behavior you want I’ll gladly dig it up and find the code for you.

As for the shape, there is a method in the control called getShape()
In here you can replace the shape, so for a box

BoxCollisionShape capsuleCollisionShape = new BoxCollisionShape(new Vector3f(getFinalRadius(),(getFinalHeight() - (2 * getFinalRadius())),getFinalRadius()));

Instead of the line for the CapsuleCollisionShape. I’ve never messed with any other than box and capsule, not sure I noticed much difference but maybe the box will help since you mentioned the rounded edges. Bunch of other shapes here: http://javadoc.jmonkeyengine.org/com/jme3/bullet/collision/shapes/CollisionShape.html

The method creates a compoundcollisionshape and adds the capsule shape to it, so I’m pretty sure if you wanted you could add multiple different shapes to the compound. I know messing with the scale has helped some people in the past with various problems.

@JESTERRRRRR
Hey, thanks for the hint at getShape(). I saw getShape, but I don’t see a setShape? So how do I replace it once I create my own shape? (I want to try cylinder) . I could possibly attach an overriding shape, but I like the replace concept you hint at.

Is the friction a property of the shape? So if I make my own cylinder, can I adjust its friction?

If you where modifying the jmonkeyengine directly, I probably don’t need the source, as I don’t want to fork away from the main releases for this. But if it was independent code, I would be interested in seeing how you solved the friction problem.

Thanks,
BigScorch.

Hi,

getShape is called in the constructor automatically, so you only need to edit getShape.

I replaced

CapsuleCollisionShape capsuleCollisionShape = new CapsuleCollisionShape(getFinalRadius(), (getFinalHeight() - (2 * getFinalRadius())));

With the line in the other post. Also the other thing I did seems really simple, not entirely sure how it works if I’m totally honest but again its just a small edit in the same file. I copied the code in the BetterCharacterControl and made a new class called MyBetterCharacterControl with it pasted in.

I’m not sure about the friction, but I seem to remember trying that and it was not pretty, had to do it for everything physics object and only while it was in the air.

What setting did you use? Seems like 90% of folks tend to pass what turns out to be really bizarre settings for size and create these giant 2 meter wide and 1 meter tall styrofoam blocks. So it’s always good to check.

@pspeed

I think cubeSettings.getBlockSize() is currently 3 in the below code. And by slide off edges, I can turn physics debug on and see, if I stand on the edge of a box, as soon as my center of gravity goes over the edge, I start to slip off. And I would prefer to stay on top and allow users to peek farther over the edge. My gravity is a big large, but I haven’t balanced that vs my charactor mass and jump force yet.

playerControl = new BetterCharacterControl(cubesSettings.getBlockSize() / 2, 
cubesSettings.getBlockSize() * 2, 0.05f);
playerControl.setJumpForce(new Vector3f(0,0.4f * cubesSettings.getBlockSize(),0));
playerNode.addControl(playerControl);
terrainNode.attachChild(playerNode);
bulletAppState.getPhysicsSpace().add(playerControl);
bulletAppState.setDebugEnabled(false);
bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0,-19.8f * cubesSettings.getBlockSize(),0));
playerControl.warp(new Vector3f(5, TERRAIN_SIZE.getY() + 5, 5).mult(cubesSettings.getBlockSize()));
playerNode.addControl(cam);

@JESTERRRRRR Do you mean I should write my own class inheriting from betterCharactorControl and override getShape? I don’t know why I didn’t think of that. I was just trying to use the class as is. I’ll give it a try. (If thats not what you mean, I need to know more what you are suggesting)

Thanks
BigScorch

Nah I literally created a new class and copy pasted the code from BetterCharactercontrol into my new class then used that exactly as before + with some edits.

Actually BCC is kind of made for extending/overriding to change its behavior. One of the few occasions where extending is actually a good idea: You want the same functionality but slightly different. Its a bad idea when you want additional / different functionality like “walkTo” methods or store NPC infos.

1 Like