Game Development Community

dev|Pro Game Development Curriculum

Climb Ladders, Trees, Rocks, Walls with TGE 1.5

by Afrim Kacaj · 11/13/2006 (4:42 pm) · 66 comments

Download Code File

This is my first resource so please forgive me in advance. I have been holding on to this code for some time now, hoping to make it better before posting it as a resource. Now that I had to merge it my self to TGE 1.5 I had the opportunity to clean it up a bit. However it still lacks one important feature, you can only enter the climbing state if you are facing the object. Once you get to the top and jump off, it's hard to get back on to climb down (unless you make your ladder longer than needed.)


To implement, merge the attached files with your project. You will need a climbing animation, with vertical transform. Same way you do the running animation with ground transform, you need to do the climbing animation with vertical transform. This will allow the animation speed to change with velocity.
Call the animation anything you want as long as it has the word climb in it and add it to your player.


You will also need an object to climb, you can use any DTS shape. Make sure your DTS has a collision box and as tight to the object as possible. Make the appropriate changes to the ClimbableObjects.cs script file.

i.e change shapefile = "~/data/shapes/ladders/ladder.dts"; to shapefile = "~/data/shapes/YOURFOLDER/YOUROBJECT.dts";

Optional: Add the following code to server\scripts\player.cs after the Armor::onLeaveLiquid function.

function Armor::onStartClimb(%this, %obj, %ClimbObject)
{
   //Dismount the weapon here
   %obj.lastWeapon = %obj.getMountedImage($WeaponSlot);
   %obj.unmountImage($WeaponSlot);
   %obj.setArmThread("look");
}
function Armor::onEndClimb(%this, %obj)
{
 //Remount the previous weapon here
 %obj.mountImage(%obj.lastWeapon, $WeaponSlot);
}

Go into the mission editor and place your shape in the mission, make sure that it is in an angle less than 90 otherwise it will not work.

About the author

Recent Blogs

#21
03/20/2007 (8:16 pm)
You mean you want me to upload the entire game engine and the starter.fps? I have made tons of other changes to the engine and starter.fps that are particular to my game since I posted this resource.

You are not placing your climb object in the mission as a static shape are you?
#22
03/20/2007 (8:58 pm)
Yes, i've created a static shape. What's the problem with that? I'm kind a newbie with Torque.
I just need the starter.fps .cs files, not the entire game engine. Sorry if I was misunderstood.

Best regards,

JM
#23
03/20/2007 (9:11 pm)
The .cs files are included in the resource, look at the folder called scripts.
#24
03/21/2007 (5:27 am)
What's the problem with placing the climb object as a static shape? How should I place it?

Best regards,

JM
#25
03/21/2007 (5:43 am)
Because a static shape will not take on the object properties defined in ladders.cs file.i.e the object will not be a ClimableItemObjectType, it will be a StaticShapeObjectTypetype instead. In other words the engine will not know that your shape is climable.

Assuming that you followed my directions above, in world creator choose shapes>ClimableObjects>Ladder to place your climable object in the mission.
#26
04/26/2007 (1:23 am)
I am working on your resource and very appreciate your hard work on this.
Your resource works great for me except one problem.

I am having a hard time finding where to control(in code) the players position on ladder.

Our problem is; The player can get on the ladder(in other words, tries to start climbing), but can not climb up the ladder. So we spend time to figure out where to control the players position which we couldn't get to find.

Do we have to make our own code to control players position? Or am I just confused?

I want to know if ther is a place in code to control players position moving up & down on ladder. Right now I am taking closer look at UpdateMove() Function.
#27
04/26/2007 (1:26 am)
I hope you can understand our problem.

We will look forward for your answer.
Thank you.
#28
04/26/2007 (3:17 am)
Adole, there is no need for controlling the player position on the ladder. Since he has started to climb, you only have to keep looking the ladder, and pressing the "up" button (for climbing up, and the opposite for climbing down). If you look somewhere else instead of the ladder, the player will fall.

Have you followed all the steps (recompiled torque engine, included the new item type, etc)?
If you still can not get the ladder working, I could send you a working version of it, for you to test.

Best regards,

JohnTex
#29
04/26/2007 (6:14 pm)
@ John

Thank you very much for your suggestion.

But I believe we tried everything you have mentioned.

Even though we pressed "up" button the player won't climb up from the begining of the ladder with the player keep facing the ladder. (but the animation of climbing is played but won't go up)
And in fact we did recompile torque engine and included new item type.

It would help us a lot if you can send us a working version of it.
We can track down what we're doing wrong and get to fix it reasonably.

Thank you again for your help, we deeply appreciate it.
#30
04/26/2007 (7:26 pm)
Please send your contact to my email (jmxntg@gmail.com).
I'm a little busy these days, but I will try to send you my working application as soon as I can.

Best regards,

John Tex
#31
04/26/2007 (9:57 pm)
Adole, it sounds like the object that you are trying to climb is not a climable object. Please read all of the instructions, including comments posted by me and other users here and you will understand.

Just to clarify (or maybe confuse you further) what we are doing here is not really climbing but walking on a very steep surface. It is controlled by this line of code: *run = bestVd > mDataBlock->runSurfaceCos || mClimbing; We override runSurfaceCos by mClimbing when mClimbing is true. mClimbing is only true when you are facing a climable object and colliding with it at the same time.

runSurfaceAngle is a property in your players datablock which defines the maximum slope that your player can climb. runSurfaceCos is the cosine of runSurfaceAngle.

So this line of code *run = bestVd > mDataBlock->runSurfaceCos || mClimbing; says that no matter what the angle of the current surface is as long as I am facing a climable object and touching it then i can walk on it.

And then elsewhere in the code we override the walk/run animation with the climb animation if mClimbing is true.

I hope you understand now what I mean by we are not climbing but walking. I dont really modify the players Z position anywhere in code.
#32
05/18/2007 (9:28 pm)
Hello all,

I am sure this will be a great resource once I figure out how to implement it to TGEA. I would like to know how I would find the code you added to those source pages so I can pick them out and add them to mine... I don't see comments to search for a common word and I don't know anything about C++ (yet....) I am slowly learning some things but I don't know anyway but to go line by line and see the difference from yours to the original. Seeing how I don't even have the same original file set I wont be able to determine your new stuff from TGEA 1.01 version. (Note: there isn't a folder dgl or a file dgl.h... my point is significant changes...)

Do you know what line numbers or... have something for me to search for in the files so I can use this? I cant overwrite the files as they are...

I hate to ask more after you went through the trouble of sharing.. but I don't know another way.

Thanks,
-G


Edit:
I found searching Afrim: got me 5 comments in player.cc but nothing in main.cc, objectTypes.h, or player.h.....
Is this all of it and nothing in main?

It would be awesome if you included a ladder.dts properly built so it could be tested. Not doubting your ability. If it wont work in a version I am using I would hate to make a unique item fitting your requirements and it wont work for me....
#33
06/19/2007 (5:07 am)
I dont know what winmerge means and i dont want to over write those engine source files because of previous engine mods. Can you explain what winmerge is or just point out what code must be added to the source files?
#34
07/03/2007 (11:51 pm)
my problem with this is that it is constantly checking to see if it's facing the object while climbing. Is there a way to delay this to check maybe only a few times a second?

in player.cpp
Con::printf("Checking if we are facing item to climb");

thats what is spamming in my console, it keeps running this loop as many times per second as it can, and it is really hurting performance in TGEA. I don't see the need to check more then 4 times a second. Can anyone offer some assistance?
#35
07/04/2007 (9:06 am)
Hey, I have two question about setting up the animation.
First, do you need to set the boundBox to move along y axis with the climb animation or along z?

And should the model it self move along z or just animate like in run animation?
#36
07/04/2007 (10:46 am)
Will, you can comment that line out. I probably put it there to see that it is working but there is no need for it. In terms of performance I dont think that its a big deal that its checking if its facing the object. I will take a look at the code once the fireworks are over to verify but I am pretty sure that when climbing you are gaining performance by not checking other things.

Jari, the player should be moving up (along Z) and since the bounding box should be linked to the player it will follow the player. In other words, just do whatever you do when you setup the run animation but instead of running you are making your player climb.
#37
07/04/2007 (10:05 pm)
ok cool, ya i didn't even think that it printing the msg to the console was what was causing the fps hit. thought it was more complex. Commenting out that line did it. lol :) next time I'll try the simple solution first. Thank you.

Now i just need to figure out how to stop the animation from looping when staying still on the ladder, and how to lower the climb speed. great resource btw :)
#38
07/06/2007 (5:31 am)
Great work Afrim and thanks for sharing!

I'm trying to use this code with TGEA but I'm having trouble with animations. I used different animations to see something happening (wave + salute for example). The animations are activated once the player reaches the climbable object, but they aren't played when the player is climbing up or down. The animations can be played forward/backward when looking up or down though which is really strange IMO...

Here's a 2.5 MB xVid video showing my problem.

Any ideas / suggestions?

Thanks

Shaderman
#39
07/07/2007 (11:31 pm)
Never mind, got it working. Need to find out the same things Will Smith mentioned above though:

Quote:Now i just need to figure out how to stop the animation from looping when staying still on the ladder, and how to lower the climb speed. great resource btw :)
#40
07/12/2007 (7:34 am)
Afrim, thank you for all the help but I still haven't gotten this working. The player animates well, the climping animation, but it stays on ground.

The only way I can raise it off ground it to animate/move it up in animation, but then it will of course just cycle up/down. So I suppose this is not the way to do it...

Do I need to setup the bounding box, is this a must?