- Home /
Slower Ladder
I've been trying to make a ladder in unity5 and have a working ladder script up theres no progression from the floor to the top of the ladder. When you go to climb it your almost like teleported to the top. How could I make it so you "climb" it instead.
#pragma strict
var playerObject : GameObject; //First person controller
var canClimb = false;
var speed : float = 100.0f;
function OnTriggerEnter (other : Collider){ //is trigger collider in front and back of the ladder
canClimb = true;
playerObject.GetComponent.<Rigidbody>().useGravity = false;
}
function OnTriggerExit (other : Collider){
canClimb = false;
}
function Update () {
if(canClimb == true){
if(Input.GetKey("w")){ //i had getkeydown but with getkey you could just walk into it and start climbing
playerObject.transform.Translate (Vector3(0,1,0) * Time.deltaTime*speed); //what makes the character move up the ladder
}
}
}
Answer by AlwaysSunny · Jun 13, 2015 at 01:54 PM
Depending on your needs and desires, it may be wise or necessary to use an animation to traverse ladders. Sounds like you don't want this, but you've still got several decisions to make about how the player controller behaves when interacting with a ladder.
Many old-school games in particular handled ladders with a simple alternate controller state.
While in this state, the character controller's response to input is drastically different. You must decide how your input should affect the character while they're "on" a ladder. This includes what input conditions move up/down, whether left/right motion is allowed, and what conditions or inputs dismount the ladder. If any lateral movement possible, it should take place relative to the surface of the ladder, whereas normally strafe input would be relative to the player's left or right.
Some sphere checking and ray casting in the player's vicinity could help determine that they've reached the top or bottom of the ladder. (Some of that same sensor code could work to allow mantling over objects, if you wanted that behavior). I guess you could do this with nothing but triggers, but that doesn't seem like a great idea.
If your current code makes the player move too quickly on the ladder, simply reduce the value of the speed variable. 100 seems like way too much; try 1 for instance. Also note the shortcut methods for cardinal directions, e.g. Vector3.up
Answer by LilacGear · Jun 15, 2015 at 02:54 PM
After uncountable cups of coffee and sleepless nights of failure I have figured out something thats passable. Set speed to like 20 (adjust to your needs)
Then replace playerObject.transform.Translate (Vector3(0,1,0) * Time.deltaTime*speed);
With playerObject.transform.position += (Vector3.up*Time.deltaTime*speed);
Some help from this
http://answers.unity3d.com/questions/296336/timedeltatime.html
Your answer
Follow this Question
Related Questions
Transform.position can't be changed smoothly. 2 Answers
Vector3 Transform.Position Not Working 2 Answers
Finding Distances With Vector3 1 Answer
distance to variable object 1 Answer
move a transform to a vector 3? 2 Answers