Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by HsomsH · Jul 08, 2016 at 12:19 PM · javascriptladder

FPSController doesn't climb ladders

I've been trying to make the FPSController (the one that comes within unity) capable of climbing ladders. I've used this script that I saw in the forums and attached it to the ladder:

 #pragma strict
 
 var playerObject : GameObject;
 var canClimb = false;
 var speed : float = 1;
 
 function Start ()
 {
     playerObject = gameObject.Find("FPSController");
 }
 
 function OnTriggerEnter (collider : Collider)
     {
         if(collider.gameObject == playerObject)
         {
             canClimb = true;
             playerObject.rigidbody.useGravity = false;
         }
     }
 
     function OnTriggerExit (collider : Collider)
         {
             if(collider.gameObject == playerObject)
             {
                 canClimb = false;
                 playerObject.rigidbody.useGravity = true;
             }
         }
 
         function Update ()
         {
             if(canClimb == true)
             {
                 if(Input.GetKey(KeyCode.W))
                 {
                     playerObject.transform.Translate (Vector3(0,1,0) * Time.deltaTime*speed);
                 
                 }
                
                 if(Input.GetKey(KeyCode.S))
                 
                 {
                     playerObject.transform.Translate (Vector3(0,-1,0) * Time.deltaTime*speed);
                 }
             }
         }
          

The variable that makes sure that the player is in range works and in fact the "useGravity" variable of the rigidbody unchecks but the character is still not able to climb the ladder. I'm new to Unity I can't figure out what's the problem.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ScaniX · Jul 08, 2016 at 01:05 PM 0
Share

I am just wondering why you use the Z key to go up and not W (forward), but you are using the S (backwards key) for down...

avatar image HsomsH ScaniX · Jul 11, 2016 at 08:59 AM 0
Share

Apparently I made a typo there. I've changed it to W but still doesn't work. I guess it's something related to the FPSController?

avatar image Eudaimonium · Jul 11, 2016 at 12:56 PM 1
Share

Your entire Update loop within ladder's script is unnecessary. Simply disabling the gravity for the player should be enough, the controls in Player's script should take care of the rest (looking up and pressing W should make you go up).

Alternatively, if you really want W/S to move you up and down regardless of look direction, implement that within Player's control script.

Also, don't use transform.Translate, try setting rigidbody.velocity first.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Ladder script not working? 0 Answers

How to make a simple ladder? 3 Answers

Player stucks on ladder (with picture) 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges