- Home /
A simple ladder in C# or Js
Hi all !
I'm very new (and bad) at scripting and i've a ladder to realize for a project we're doing with friends of mine. I've a third person character based on the "Mecanim tutorial for Unity 4.0" = http://www.youtube.com/watch?v=Xx21y9eJq1U that is a prefab and has a C# script used to move it.
I've tried to make a simple ladder script (touch a collider, climb the ladder,..., profit !) but all i have when i'm entering the collider is... no response.
I've used the following solution - http://answers.unity3d.com/questions/621651/how-to-make-a-simple-ladder.html - http://xn--m3h.net/umbrella/2010/11/unity3d-ladders/ - http://answers.unity3d.com/questions/41719/how-to-climb-up-a-ladder.html
But none of them seems to work for me
The latest code i'm trying to use is this one (attached to the ladder)
var playerObject : GameObject;
var canClimb = false;
var speed : float = 1;
function Start () {
playerObject = gameObject.Find("Cesareredim 1");
}
function OnTriggerEnter (collider : Collision){
if(collider.gameObject == playerObject){
canClimb = true;
playerObject.rigidbody.useGravity = false;
}
}
function OnTriggerExit (collider : Collision){
if(collider.gameObject == playerObject){
canClimb = false;
playerObject.rigidbody.useGravity = true;
}
}
function Update () {
if(canClimb == true){
if(Input.GetKey(KeyCode.Z)){
playerObject.transform.Translate (Vector3(0,1,0) * Time.deltaTime*speed);
}
if(Input.GetKey(KeyCode.S)){
playerObject.transform.Translate (Vector3(0,-1,0) * Time.deltaTime*speed);
}
}
}
My first question is : Did the mix of C# for my character and Javascript for the ladder work properly ? My second question is : Is it possible to create a simple function for climbing in C# that i didn't know (using a key when entering the collider of an object with a tag "Ladder") ?
Answer by Loh · Jan 24, 2014 at 10:54 AM
Okay !!!!!! I FINALLY did it !
All i have to add was
function OnTriggerEnter (collider : Collision){
if(**other**.collider.gameObject == playerObject){
canClimb = true;
}
}
function OnTriggerExit (collider : Collision){
if(**other**.collider.gameObject == playerObject){
canClimb = false;
}
}
So i hope this will help many in the future !
Answer by oliver-jones · Jan 24, 2014 at 10:47 AM
Your problem might be in your collider function:
function OnTriggerExit (collider : Collision){
if(collider.gameObject == playerObject){
canClimb = false;
}
}
Is 'playerObject' a name? or a tag? Try:
if(collider.gameObject.name == "playerObject");
Or
if(collider.gameObject.tag == "playerObject");
Answer by rasheedqw · May 15, 2015 at 06:43 PM
here is a video on making a ladder hope it helps https://www.youtube.com/watch?v=twSepOguQcI
Your answer
Follow this Question
Related Questions
Implemeting climbing ladder in unity 2d 0 Answers
Distribute terrain in zones 3 Answers
Modify tps standard script to be able to climb pipe/ladder 0 Answers
How do you climb a ladder 1 Answer
Climb ladder 2 Answers