- Home /
Trying to get FPS ladder script to work
I've been trying this code out. Which so far is the ONLY one I've been able to get any headway with. But what happens is, is that if I press Jump repeatedly I will eventually get to the top of the ladder.
Secondly, I am now able to climp terrain sloaps that are very steep which I DO NOT WANT! How can this be fixed?
That 2nd Debug does NOT seem to get called for some reason when I exit the ladder?
function OnTriggerEnter (other : Collider)
{
Debug.Log("Was Triggered");
if(other.gameObject.tag == "ladder")
{
transform.GetComponent(CharacterController).slopeLimit = 99;
transform.GetComponent("CharacterMotor").sliding.enabled = false;
}
}
function OnTriggerExit (other : Collider)
{
Debug.Log("Was a ladder");
if(other.gameObject.tag == "ladder")
{
print("leaving ladder");
transform.GetComponent(CharacterController).slopeLimit = 45;
transform.GetComponent("CharacterMotor").sliding.enabled = true;
}
}
Answer by Richard J. Hansen · May 05, 2011 at 04:45 AM
In this answers http://answers.unity3d.com/questions/31275/fps-ladder-script you mentioned that it did not work for you but did not give any details. It looks like to me that it should work.
Is the object named 'ladder?'
Are you using a standard character control or motor?
Did you play around with the slop limit value?
Try adding in some debug lines to see where it is failing.
function OnTriggerEnter (other : Collider) {
Debug.log("Was Triggered");
if(other.gameObject.name == "ladder") {
Debug.log("Was a ladder");
For example. If it never gets to the second debug line, that will give you an indication that you went wrong somewhere setting up the trigger.
All of the above my friend, I even tried boosting that slope limit right up to 99! All it did was make my FPS player able to climb terrain slops which I sure as heck don't want as I'm trying to keep the player within certain bounderies. But climb the game object tagged and even named "ladder" Nope, nadda, zippo?!?! The Big Fail ;)
Were you manually changing the slope limit, or was it not changing it back? Did the debug lines reveal anything?
You could also add after the if name == ladder line something like "if forward axis is positive, position.y+=climbspeed.' Assu$$anonymous$$g the script is getting to all of the debug lines I suggested I imagine this would work just as well without fidling with slop values. (probably need to turn off gravity while in contact with the ladder as well). Let me know if you would like it in an actual script. If so I will write somethign up and edit it in to the answer.
Thanks Richard, yeah if you could whip me up something that works that would be awesome! I've been striking out left and right with this whole ladder stuff :D
I tried this out again just to give it one more shot. Now this is kinda strange. I added the debug stuff. It says "Was Triggered" The 2nd debug seems to never get called. If I keep hitting jump repeatedly I will eventually get to the top of the ladder. But I am also now able to climb the terrain sloaps which I don't want!! how can this be fixed??
Your answer
Follow this Question
Related Questions
How to climb up a ladder!! 1 Answer
Is this how a ladder collider works? 1 Answer
How to make a ladder script for unitiy's FPS controller? 1 Answer
3rd Person Ladder/Wall Climb Script 1 Answer
Climbable ladder for 2D game 2 Answers