0
$\begingroup$

I came up with a really easy way to script climbing a ladder in Game Engine. It basically just involves colliding with the ladder (which toggles a "Climbable" boolean) and then when you hold up or down to ascend/descend the ladder it temporarily sets Gravity to 0 (bge.constraints.getCharacter(obj).gravity = 0) so that the player isn't pulled downwards by gravity while they're clinging to the ladder. From there, I was smart enough to make it so if you press a side direction and aren't touching the ladder anymore there's an "Inverted" Collision with the ladder that makes it so if you aren't touching a ladder the Climbable boolean is always False and gravity immediately returns to normal (29.399999618530273, by default). All works properly as intended.

I have a problem though. If I jump onto the ladder or if I simply fall off of a platform onto the ladder and try to climb, it won't work as intended. If my character is jumping upwards to a ladder and I hold up to climb, then he will fly upwards like a rocket (on account of the zero gravity) and if I try to climb up a ladder while actively falling. The drag of falling will keep pulling my character downwards as he tries to climb and the drag continues until he collides with the floor (zero gravity doesn't negate downward force for some reason)

I need some way to "turn off" the falling behavior of a character and the upward motion of a jump on-the-fly so that my ladder scripting works properly. I can't figure out how to get them to stop. If anybody knows some line of code I could use to get him to stop, I would greatly appreciate it.

bge.constraints.getCharacter(obj).onGround is a "read only" boolean, so I can't use that to trick the game into thinking I've landed on ground. I've tried.

I am using Character Physics for my player character.

$\endgroup$
  • $\begingroup$ Let me add by saying that I actually don't want climbing a ladder to be treated as a "onGround" state, I don't want you to be be able to jump while on a ladder. I really only mentioned it because I figure it could've been a workaround. $\endgroup$ – revengeofthemadmadman Aug 10 '16 at 10:27
  • $\begingroup$ I don't know much about BGE, but your method sounds awfully complicated. Using gravity does make things quite unpredictable. I'd go with the method that is described in this video: youtube.com/watch?v=4v--_GtSbD4 Besides... you can also use the edit link below your post to add information to your question (preferred method). $\endgroup$ – metaphor_set Aug 10 '16 at 12:02
  • $\begingroup$ You don't see it in his video, but I'm very certain that he has the exact same problems as me. If he were to jump into the ladder and go up, he would get the same issues that I'm having. Also, do take notice to parts of the video where he releases from the ladder early, how his character cube doesn't cling to the ladder at all because he hasn't edited for zero Gravity or implemented some other way to force the player cube to stay in place. My method is more complete than his. As for Radar vs Collision, that's a matter of preference. $\endgroup$ – revengeofthemadmadman Aug 10 '16 at 13:33
1
$\begingroup$

The way you implemented a solution is that the object has no gravity.

This is not really the behavior of an object that "holds on another object" (character holding at the ladder).

You currently discover "an area without gravity". That means when the character jumps into that area it will preserve it's motion and direction (while gravity would would do the same but adds another force influencing motion and direction).

I suggest you implement a "holding" onto the ladder, e.g. by parenting the object to the ladder [or any other way to restrict the position to the holding point].

While holding any previously active controls (like jumping, walking crouching) will not work anymore as the character is not a freely moving physics object. This is fine, because your character holds itself to the ladder.

You need other "operations" like move up/down (but not via linear velocity and such things). Additional you should implement a "release operation" that let the character release the grip returning to the normal behavior (incl. falling).

Other operations could benefit from release too - you can combine jump and release. I suggest to first release and jump afterwards. Otherwise the exiting "hold" would disable the jump.

What problems could happen?

A) Parenting is a hard attachment. This means when you throw the ladder around, the character will not care and still hold onto it. If you really need such situations, you could release the character before (or while) moving the ladder.

B) The character ignores collisions while moving on the ladder. While parented the physics has no influence. Unfortunately there is not much you can do here, except sensing for such collisions and acting accordingly. E.g. you sense if there is a blocking object above the character before allowing the "move up" operation.

I hope this helps a bit.

$\endgroup$
  • $\begingroup$ I always appreciate your advice and for answering my pleas for help and I thank you for your knowledge and advice. I apologize for taking days to respond to you, as I've been working on this off and on and didn't want to bother you until I solved it. I've decided to create my own scripts for jumping and falling, to not use Character Physics anymore at all, and doing this has solved all of my problems. You just do not get enough control over your character using the built-in Character Physics and do anybody reading this, I recommend writing your own character jumping/fall scripts too. $\endgroup$ – revengeofthemadmadman Aug 16 '16 at 0:54
  • $\begingroup$ Ran out of space in the last comment, continuing. I did take your words to heart and desperately tried to implement a "holding" mode like you've suggested, but it's not something I think can be done. There's always going to be drag on the character that pulls them down if they're affected by gravity. My way is very similar to how I started, I simply turn off the upward/downward forces of a jump or falling when I want my character to climb a ladder and he snaps to the center of a ladder while he's in the climbing state. All works dandy now. None of this answers the original question though. $\endgroup$ – revengeofthemadmadman Aug 16 '16 at 1:01
  • $\begingroup$ When you parent the character to the latter it will become static. The gravity will not effect the character anymore. That is why you need different movement logic while on the latter (dLoc rather than linV). $\endgroup$ – Monster Aug 16 '16 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.