I had already tried BetterCharacterControl, but I wasn’t able to use .setPhysicsLocation(); beacuse it was protected, is there a way to acheive the same result as .setPhysicsLocation(); while using BetterCharacterControl?
I was also trying to avoid using jump() altogether, because I wanted to have different forces applied to the player1 depending on if it was travelling up or down. (Like in mario 64, where mario takes 18 frames to reach the apex of his jump, but only 10 to fall again.)
You get the physicscontrol. But I mean… the jump method does that already. You’re trying to fight against the physics system. The only way to it internally is set the gravity lower before you jump and higher as you fall. It’s a weird setup.
In the real world it would take roughly the same time to reach the peak of your jump as it would to hit the floor from the peak. Like a parabola. The only way to alter the physics simulation is to change the parameters for which it calculates. Otherwise you’re gonna have a really hard time with jittering and other unwanted side effects.
Actually after a bit of thought, in order to retain behaviours it would probably be best to invoke a slight negative impulse at the peak of your jump instead of gravity.
If you change gravity or mass to get it to drop faster, your character would behave differently on the downward movement if something hit it or it collided with something, but if you just applied a small impulse downward everything would remain the same whilst still getting the effect you need. With the benefit of not having to change values when you’re going up and down hitting the floor again. Makes things a lot less complicated.
From recent research, I know way more about this topic than I probably should… but a lot depends on what kind of jump you want in the end. (I even implemented several types in the sio2 bullet character demo.)
Setting the upward velocity to a jump velocity is the typical approach. You only need to kill the velocity at the “top” if you want the effect of ‘early termination’ in the case of the player stops pressing the jump.
Lots of articles on this related to 2D jumps which translate (mostly) directly. From my own recent research:
For BetterCharacterControl look into it’s controlUpdate Method, it dampens all forces and also applies a jump impulse there, you want to change that to apply a force over a given amount of time and after that cancel the force or even use a counter force
Note that the best solution would be to move that code into the CustomCharacterControl.
Btw usually you’d only have to apply an impulse once and applying it multiple times (like in your code) would lead to even more speed (usually you’d also have to multiple that with tpf to have it framerate independant at least).
This works in that case, because BCC is removing all forces every frame and applies the walk force again, that is also the spot where you’d have to add your applyImpulse