Making a CharacterControl work with two unusual mechanics

Hi all,

Recently I discovered JMonkey and I enjoy the simplicity of it quite a bit. Loading and manipulating 3D models has been a lot easier than in any other game Engine I worked in thus far. After trying out the tutorials me and the rest of my team decided to use it for our school project. About three weeks into the process, it became clear to me what the game’s mechanics were supposed to be: The character is supposed to be able to both double jump (sort of like how it works in Super Mario Sunshine) and be restricted in movement by a chain (imagine something like you being a dog attached to a doghouse that can only run so far).

Under normal circumstances, this would be a no-brainer: Use CharacterControl to walk through the world. Obviously that does not work with the mechanics described above, since A) A CC can only jump once and only when on the ground, B) The chain, despite having realized this using ConeJoints, can never be attached to a CC as it only works between RigidBodyControl instances and finally C) the mechanics together would not work well; the case in which a character has gone as far as the chain allows it to during a mid-jump, as a jump cannot be cancelled (as far as I know at least).

I have actually tried several things to realize these mechanics. One way to realize the double jumping was to try the ForceCharacterControl class posted in another topic. I sort of got what I wanted with that, but not quite, since ApplyCentralForce adds to the velocity and I want to be able to clear it prior to using the double jump (so that there will be no unpredictable results), as well as being able to clear it when the end of the chain is reached. Making the CC able to walk into the direction it is about to go to if the chain would reach its maximum stretch seems like an option as well, but how would I go about doing something like that?

So my question is: What is the way to go if I want to have this kind of control over my character? I need to be able to use these mechanics, but I also want the benefits provided by CharacterControl (such as it being unmoveable, checking for grounds, walking up the steps). One option that is worth considering is to create my own variation of CharacterControl using for example a kinematic body, but it seems like some complex math is involved using vectors (such as climbing up the slopes) and I am far from advanced with that, so I have no idea how to go about doing that. If anyone can provide any pointers on how to realize this, it would be greatly appreciated (hopefully also by future visitors that might have tried before).


I think you should not have them attached at all.

Make the chain attached to the character just for the visuals. But in reality you modify the characters velocity.

In the updateloop check

[java]if (his distance is > chainlength){

his velocity = chainpolePosition.subtract(his position).normalize().mult(his velocity.distance(Vector3f.ZERO));[/java]

Think this should get it somewhat real feel of a static chain…

Tell me what you think :slight_smile:

If I understand well, you mean that the character should be confined to a virtual circle of which the chain pole forms the center, right? I’m afraid that this is not an option. The first thing is: The chain should really behave like a chain. Imagine there would be a pillar a short distance away from the chain pole and the character would run around it, and back. With the option presented above, that would mean that the distance just decreases again. In a realistic situation, if you were to run around a pillar while a chain was attached between you and a pole, the chain would wind around said pillar and restrict you even more (if you know what I mean). Even considering it as an alternative, how would I stop a (Force) Character Control’s velocity mid-jump?


The sort of chain you are describing is actually really complicated to model correctly. I really recommend trying to simplify it for your first project.

What would you suggest as an alternative that still works relatively well the way I want it to (maybe discarding the realism of the chain a little)? And is there a way to make it potentially work with the other described mechanic (double jumping)?


If you must have that it can be wired around a pole I suggest you use my previous method still, but moddify the chainlength aswell.

Give the pole a radius and as he rotates around it, remember how far he has gone.

Then using some quite simple math you should get the remaining chainlength.

Maybe if you have the chain as a physical chain you can get it to look like it’s being wrapped around a pole, but dont use it as a force to drag the character.

As Addez says: Do the movement constraints separately from the display of the chain. If you want to “wrap” around something then detect the wrap and constrain in a smaller radius from that wrap point. You will need to work out a way to “unwrap” too…so really unless its vital to the game design I’d avoid the whole wrapping problem.

Second: Display the chain graphically using the points worked out in the movement.

For double jump just look at how jump works and make it possible twice.

As far as the double jumping is concerned: I looked into the character control and tried to do something really simple like extending CharacterControl and KinematicCharacterController. That way I can override the jump() method of the KCC class. It seems to work well at first, but there is a weird issue. If I do not call super.jump() within the overridden jump() method and instead use only verticalVelocity = jumpSpeed; (which I found within the java doc of the KCC class) then my Character does this weird power-slam kind of thing after reaching the tip of the jump (In other words: going downwards really fast, beyond the fall speed I set for it).

I guess I will just call jump() on the superclass and only set the verticalVelocity when it is not on the ground, it seems to work well with that. Still, it seems pretty weird.