Collision detection

Hi

I am making a ladder script that will hopefully findout if you are colliding with a objected taged as a “Ladder”. If the Collision is with the “Ladder” then if the player presses “W” the player will assend. With the help of others I have achived the W assending. The issue has now arrisen when I have added the collision detection. Before posting on here I have made sure the the Ladder has been given the correct tags.

using UnityEngine;
using System.Collections;

public class Ladder : MonoBehaviour {

	bool wPressed = false;
	bool insideTrigger = false;
	bool autoPilotStandard = false;

	void Update(){
		if (insideTrigger){
			if (Input.GetKey(KeyCode.W)){
				wPressed = true;
				float translation = Time.deltaTime * 2;
				transform.Translate(0, translation, 0);
			}
			else{
				wPressed = false;
			}
		}
		if (autoPilotStandard) {
			float translation = Time.deltaTime * 2;
			transform.Translate(0, translation, 0);
		}
	}
	void OnCollisionEnter (Collision collision){
		if (gameObject.tag == "Ladder") {
			insideTrigger = true;
		} 
		else {
			insideTrigger = false;
		}
	}

}

OK you need on OnTriggerEnter to set your bool to true and OnTriggerExit to set it to false.

The only time this isn’t going to work is if your player dies in the trigger but as you probably instatiate a new player I don’t think that’ll be an issue for you.

Hello,

attached Rigidbody component to gameObject may be miss.