- Home /
Climb Wall: How do I change key input from horizontal to vertical?
Basically I have a character with a Third Person Controller who I want to be able to climb up walls if they are climbable (and if climb is enabled on character). The character is only allowed to climb for a few seconds at a time, then he should just fall back down if he hasn't reached the next ledge up. I figure I can use a trigger or something similar to detect the wall, and then check the character to see if climb is enabled. What I can't figure out is how to change the up arrow to move up instead of forward. To be precise, I want the character to face the wall, and change the key to move straight up instead of forward (or just use a different key). left and right (while climbing) should move the character left or right along the face, while still facing straight forward. Back should drop from wall. Been struggling with this for awhile, really appreciate any help, thanks.
Answer by AngryOldMan · Feb 28, 2011 at 04:30 AM
I think this is basically what lllogical is saying. under your input.getaxis vertical (the one to move the character forward) include an if statement that changes the direction your input alters. eg (sorry for forum code) in your "PlayerMove" script
//Static var means its a global variable (other scripts can access and change it) static var Onladder : boolean = false;
if (Onladder == false)
{
moveDirection = Vector3(Input.GetAxis("Horizontal"),Input.GetAxis("Vertical"),0);
}
if (Onladder == true)
{
moveDirection = Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
}
then on the ladder object/trigger area. (make sure your player is tagged player)
//assign your player prefab in the inspector! var playerPrefab
function OnTriggerStay (collision : Collider) { if (collision.gameObject.FindWithTag ("Player")) { ClimbLadder = playerPrefab.GetComponent(PlayerMove); ClimbLadder.Onladder = true; } }
yes there are shorter ways to type this code so please don't waste your time code bashing my post. i believe this is a very obvious way to show how the script is working minus all the extra jargon you can (if you so choose to) use to shorten scripting amounts.
Thanks both! took a while for me to get back around to this, as I've been spending my time on enemy AI's.. Thanks for the example Bobadebob, I had made some progress since my original post, but was having trouble getting the trigger to act right.. your suggestion looks like it should fix my current issue.. Thanks again!
Answer by Illogical-Ironical · Feb 27, 2011 at 06:36 AM
Change Input.GetAxis("Horizontal") to Input.GetAxis("Vertical")
Make a code that switches the W/Up key's movement to vertical when touching the wall.
I hope that's of help, or at least gives you an idea of what to do.
Your answer
Follow this Question
Related Questions
Spider Wall Movement Between Waypoints 1 Answer
Programming Wall Climbing 1 Answer
Rigidbody sticks to wall 0 Answers