Game Development Community

Climbing ladders, ropes, walls, etc.

by Afrim Kacaj · in Torque Game Engine · 12/23/2005 (9:52 am) · 37 replies

I would like to implement ladders in my game so that I don't have to use stairs in towers. (If I used stairs my towers would have to be wider, which is what I don't want)
So I have seen a few dead threads dealing with this issue but none seem to have the answer. I was wondering if anyone has been able to implement climbing and how.

The issue is not how to detect stairs as that can be done with collision or a "Operate" key so that when pressed you do a line test to see if there is a ladder within reach.
The issue that I am having is how you get the player to move up/down. I have seen threads that suggest modifying the player's gravity, but that doesn't sound reasonable. In real live when you climb a ladder your gravity remains the same. Changing the players climbable surface angle makes more sense but when I set it to 90 I still can not walk up a ladder (unless I tilt the ladder slightly).

Anyways I would love to hear how you have implemented this.

Thanks,

Afrim
Page «Previous 1 2
#1
12/23/2005 (10:48 am)
Well, it's only really for adventure-or RPG games rather than fast action-ladder climbing/etc, and not really for first-person games...either.

Create "getting on the ladder" "climbing up" "climbing down" and "getting off the ladder" animations. Then, trigger the "gretting on the ladder animation", lock the keyboard input so that nothing interrupts the trigger, then activate the "climbing up" animation and change the player's world position to "raise" them. Then trigger the "get off the ladder" animation at the top.

I did something similar to this quite a while back and I'll be revisiting this here soon.
#2
12/23/2005 (11:00 am)
Afrim,

David's solution sounds good. But just to explore the options, here is another possible method, from a different, slightly warped, perspective.

This will probably sound strange, but I would try using a variation of a jetpack system for ladders and ropes. That will get characters moving vertically. It would use the mJetting functionality described in several resources -- I would call it mClimbing or something like that. The climbing ability could be switched on and off using trigger objects. Also, a climbing animation could be assigned to the character while the player moves up or down on the ladder.

I'm sure there are several other ways to accomplish the effect, but this is the way I'd approach it.

I hope that helps,

Aaron E.

[Edit: some typos]
#3
12/23/2005 (4:55 pm)
Thanks for your posts guys.
Here is how i plan on doing it, let me know what you think!

Create ladders in the world with a slight tilt, say 85 degrees.
When the player collides with the ladder do a raycast to see if the player is facing the ladder
if he is facing the ladder
then set his animation to climb_root, if moving then set his animation to climb
set his max run surface angle to 85 or above
if he is not facing the ladder then give him a little push to fall off the ladder and set his animation and max run surface to normal.

if player was midway on the ladder the engine would take care of his falling animation etc. if he climbed to the top (the ladder should be a bit taller than the next floor) at some point the raycast will return false and thus we give him a push off the ladder which should set him to fall on the next floor.

Does that make sense?
#4
12/23/2005 (10:28 pm)
Ladies and gents, its aliveeeee! The code below is what I have got so far and it seems to work better than expected! I haven't added the animations yet (waiting for my artist to create them) but I would imagine that its going to be a piece of cake setting the climbing animation if the player is facing the ladder and colliding.

The only problem that I am facing now is how to change the player's runSurfaceAngle from script. As far as I know Datablock properties are static. Is there a function that will do it? I guess I can derive a new Datablock from the player with the changed property but that sounds dirty and it would defeat the purpose of Datablocks. Also changing the players datablock resets their energy and power levels.

Any help is appreciated!

//Ladders.cs
datablock StaticShapeData(Ladder)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
category = "Ladder";

// Basic Item properties
shapefile = "~/data/shapes/ladder/ladder.dts";
mass = 1;
friction = 1;
elasticity = 0.3;
};


function Ladder::onCollision(%this,%obj,%col)
{
// messageClient(%col.client, 'MsgLadderCollision', '\c2You collided with a ladder');



%eye = %col.getEyeVector();
%vec = vectorScale(%eye, 2);
%start = %col.getEyeTransform();
%end = VectorAdd(%start, %vec);
%found = ContainerRayCast(%start, %end, $TypeMasks::StaticObjectType, %player);


if(!%found)
{
%position = %col.getPosition();
%impulse = -1000;
%impulseVec = VectorScale(%eye, %impulse);
%col.applyImpulse(%position, %impulseVec);
}

}
#5
12/24/2005 (12:12 am)
Quote:Well, it's only really for adventure-or RPG games rather than fast action-ladder climbing/etc, and not really for first-person games...either.

Battlefield 2 has changed that.
#6
12/28/2005 (10:24 am)
After playing around with the above method I realized that it does not work as well as I first thought. The big reason is that the onCollision function is not called when the player reaches the top of the ladder (or when he is walking on top of the ladder). So it depends on how the player climbs the ladder if they just hold the W key down the player moves up too fast and there is not enough time for the ContainerRayCast function to be called and therefore the player will not be colliding anymore and the datablock remains as the new one (where he is able to climb anything).

So now i need to dig into the C++ code and modify the player.cc file. What i need is to expose a method that will allow me to change the players climable surface from script (Without changing the datablock).
#7
12/28/2005 (12:05 pm)
@Afrim

I've been toying around with a few different ladder implementations for a while now. However, i'm not too keen on the C++ side of things. Do let me know what you find though!
#8
12/28/2005 (9:44 pm)
I have made some progress with this issue, all thats missing now is my animations. I ended up using a combination of trigger/collision/c++ modification to add a console method.

When the player enters/leaves the trigger I call a console method to modify the climable surface angle.
I use collision to determine if the player is facing the ladder or if he entered the area while facing some other direction. If he is not facign the ladder i bump him so that he cant climb, if he is facing the ladder then he can climb.
When he leaves the trigger his climable surface angle is set to normal so that he cant go climb other things.

There is only one trigger with the same size as the ladder.

Next step is to change the animation when the player enters the trigger, that may require that i change the whole thing but ill keep posting here untill i find the best solution.

In any case this works even if i dont get the animations, at least i dont have to use stairs now.

The only thing i dont like about this is that from a designers point of view it sucks. For each ladder you have to create a trigger object as well as a ladder static shape. I wish triggers had a way to assign a shape to them in one step.

The only thing that makes triggers apealing in this case is the onLeaveTrigger function because thats where i can set the players settings to normal. All of this could have been done with a StaticShape object and its onCollisionFunction but there is no way to know when the player is not colliding anymore unless i schedule a check but i think that might get ugly.
#9
12/29/2005 (11:05 am)
My next approach to this problem is as follows:

I need to make this change in the C++ code:
If the player is moving forward on a surface that has a pitch higher than 85 degrees then play his climbing thread. Make the player always paralel to the surface as he climbs.
Move the players RunSurfaceAngle member from the datablock to the player class and expose it to the console.

From script add triggers anywhere where you would like the player to be able to climb.
The triggers onEnterTrigger will change his RunSurfaceAngle to 90 degrees.
The triggers onLeaveTrigger will change his RunSurfaceAngle back to normal.

This approach will allow the player to climb anything that has a pitch < 90.

To make it more interesting, I can even add decals where his hands touch the surface to make it look like he is cracking the surface he is holding on to (like in the incredible hulk game for xbox).

Would anyone like to recomend where in the Player class i should look to implement this stuff?
#10
12/29/2005 (3:55 pm)
I was looking through the Quake III source code, just for ideas, and it seems that they have the ladder checks in the Player's movement code. I don't quite know where that is in Torque, but might it help?
#11
12/30/2005 (2:42 am)
Interesting stuff. Thanks for keeping us updated on your progress.

Nick
#12
01/07/2006 (1:24 pm)
Do u think it would be possible to send me a resource? i am also trying to make climable walls, rops and ladders for my rpg game (for personal use only, i am a single person and its more of a hobby then selling games). it would help me a lot,

my e-mail is in my profile,

i would be deeply greatful:)
#13
01/07/2006 (2:19 pm)
Climbing things is something that should be done almost entirely in C++; maybe have some script controller methods for it. You could probably hack climbing in in less than an hour. Having a robust system with multiple states(rope, wall, or ladder; play different animations), support for things like sliding down/repelling, and other cool stuff will be harder. Frankly, you'd be better off to rewrite the Player class(no, it's not that complicated!) if you're aiming for an "advanced" system.
#14
01/07/2006 (4:19 pm)
Actually i have made some improvements on this, done entirely in C++. I am thinking about creating a new class derived from shapebase called climablesurface or something. Or I can just use shapebase; its datablock has a field called dynamic type that i think i can use. Baisically I need a way from script to tell the engine that this shape should be climable. And in the engine i do a check if player standing on climable surface then switch his animation etc. His animation is controlled just like the run animation. In other words i use his vertical velocity to determine animation speed. If his velocity is 0 his animation pauses if he moves down his vertical velocity would be negative and therefore his animation would play backwards. So all thats needed is a single climb animation.

I also have to call a script function from C++ telling the script when the player is climbing. So that you can than handle the weapon dismounting while the player is climbing (unless you want him to climb while holding his weapon).

I have to do some more work on this, once its finished I will post it as a resource!
#15
02/08/2006 (7:20 pm)
I'm looking for something similar, but more general purpose...
I'd simply like for a vehicle/player/whatever to be able to climb any surface, orienting itself to the surface normal.
The only time gravity would be used was if the object was out of reach of any surface,jumped, etc.
#16
02/08/2006 (7:42 pm)
I have finished this, sorry forgot to update the thread. I am currently working on a master server, once thats finished I will post both the Climb implementation and Master Server as seperate resources.

Player will climb anything that you mark as climable in script. Only one climb animation is needed, it will play forward, reverse or stop based on the players vertical velocity. Everything is done in C++ with very little overhead. I just have to add a script callback so that you can handle the weapon dismount (if needed) while the player is climbing.

You can climb a ladder, house, wall any staticshape as long as you set the dynamicobjecttype property of the staticshape datablock to climableobjecttype.
#17
02/08/2006 (7:55 pm)
So Afrim, do you have the code available, that you are willing to share?
#18
02/08/2006 (8:43 pm)
Yes but i didnt feel like explaining it yet untill i am ready to post a resource. This is also a public forum so I dont think i can post it here.
#19
02/08/2006 (8:50 pm)
Yes, you're right. I'll wait for the resource then.
#20
02/08/2006 (10:45 pm)
I look forward to accessing the resource when its done. I've flagged this thread so if you can post here when it's up it would be much appreciated.
Page «Previous 1 2