Hi Unity Community! I’m fairly new to scripting and I am currently trying to make a ladder that the character controller can walk up to and press up to go up, or down to go down. I would also like that character to hold their Y position when not pressing anything (i.e. holding onto the ladder at a static height). Unfortunately, I don’t seem to have a good grasp on the Vector3. This part of the code: PlayerTransform.transform.position+=(Vector3(0,Speed* Time.deltaTime,0));
causes the character to either only go down or go up. If I use 1 instead of Speed * Time.deltaTime the ladder works but is way to fast, I have also tried using decimals but once again, they seem to direct the Player down only and very quickly. Why don’t the Vector3s work the way I am expecting? Below is my complete code:
var Speed : float;
var Player : GameObject;
var Height : float;
var PlayerTransform : Transform;
function Start(){
Player = GameObject.FindWithTag("Player");
PlayerTransform = Player.transform;
}
function Update(){
Height = Player.transform.position.y;
}
function OnTriggerStay(other : Collider){
if ((Input.GetAxis("Vertical")>0) && other.name == "Player"){
PlayerTransform.transform.position+=(Vector3(0,Speed* Time.deltaTime,0));
}
else if ((Input.GetAxis("Vertical")<0) && other.name == "Player"){
PlayerTransform.transform.position-=(Vector3(0,Speed*Time.deltaTime,0));
}
else{
Player.transform.position.y = Height;
}
}
have you tried lowering the value for "Speed"?
– zBlancoSo far, the problem is that if I use a value of less that 1 for "Speed" the only direction the ladder works is down. I'm not sure why.
– Dicktanner