Hi. Im trying to make a 2D game, which will have ladders- but its not working. There are no errors. But its not working Heres my script, which I put on character.
var speed = 3.0;
function OnCollisionEnter(Bam : Collision)
{
if(Bam.tag == "Ladder")
{
var controller : CharacterController = GetComponent(CharacterController);
var forward = transform.TransformDirection(Vector3.up);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
}
}
That didnt work at all, even when i added Debug.Log s
Then i tried
var speed = 3.0;
function OnTriggerEnter(Bam:Collider){
Debug.Log("Checking for ladder");
if(Bam.Tag == "Ladder"){
Debug.Log("Touching Ladder..");
var controller : CharacterController = GetComponent(CharacterController);
var forward = transform.TransformDirection(Vector3.up);
var curSpeed = speed * Input.GetAxis ("Jump");
Debug.Log("Variables for movement made!");
controller.SimpleMove(forward * curSpeed);
Debug.Log("Moving Ready!");
}
}
Now im being spammed with Checking for Ladder- Yay! but It still doesnt detect a ladder and execute in the log here:
OnCollisionEnter is not a update… You might want to use OnCollisionStay or when hitting the ladder setting a bool to true that does the same thing as when you hit the ladder (but then in the update function) and setting the bool on false at OnCollisionExit