Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Shogun · May 03, 2011 at 07:54 PM · charactercontrollerfalling-through-floor

Character Controller falls through ground when not using Input.GetAxis()

I have a small problem with controlling a character with a Character Controller when not using Input.GetAxis()

I prefere to use Input.GetKey() for all (or most) of my input, but the problem is when i don't use Input.GetAxis() the character falls to the ground but then just sort of disapeares after about half a second.

I don't understand why it would work with one but not the other.

var playerSpeed : float = 6.0; var playerGravity : float = 20.0; var playerJumpSpeed : float = 8.0;

private var playerMove : Vector3 = Vector3.zero;

function Update() { var controller : CharacterController = GetComponent(CharacterController);

 if (controller.isGrounded) {
     if(Input.GetKey(KeyCode.T))
     playerMove = Vector3(0,0,1);

     if(Input.GetKey(KeyCode.G))
     playerMove = Vector3(0,0,-1);

     if(Input.GetKey(KeyCode.F))
     playerMove = Vector3(-1,0,0);

     if(Input.GetKey(KeyCode.H))
     playerMove = Vector3(1,0,0);

     //Works with this line...but not the above code
     //playerMove = Vector3(Input.GetAxis("Horizontal"), 0,Input.GetAxis("Vertical"));

     playerMove = transform.TransformDirection(playerMove);
     playerMove *= playerSpeed;

     if(Input.GetKey(KeyCode.J)){
         playerMove.y = playerJumpSpeed;
     }
 }
 playerMove.y -= playerGravity * Time.deltaTime;
 controller.Move(playerMove * Time.deltaTime);

}

It just seems strange that one will work, but the other will give me some very strange results :/

anyone else had problems like this or is it that you have to use Input.GetAxis()?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by benni05 · May 03, 2011 at 08:11 PM

Input.GetAxis returns a value between -1 and +1. Not just -1 or +1, please check this out through

Debug.Log(Input.GetAxis("Horizontal"));

in one of your Update methods and have a look at these values. So probably your game scale doesn't fit to those hardcoded -1/+1 values you get when using the t,g,f,h keys.

Ben

Comment
Add comment · Share
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
0
Best Answer

Answer by Shogun · May 03, 2011 at 09:21 PM

Reading your answer i managed to fingure the problem out. With Input.GetAxis() you are always getting value being passed 'playerMove'...

With my code above i was only passing a value (1 or -1) if a key was being pressed. I made some changes to the code above...

[snip...]
        if(Input.GetKey(KeyCode.UpArrow)){
            playerMove = Vector3(0,0,1);
        }
        else if(Input.GetKey(KeyCode.DownArrow)){
            playerMove = Vector3(0,0,-1);
        }
        else if(Input.GetKey(KeyCode.LeftArrow)){
            playerMove = Vector3(-1,0,0);
        }
        else if(Input.GetKey(KeyCode.RightArrow)){
            playerMove = Vector3(1,0,0);
        }
        else{
            playerMove = Vector3(0,0,0);
        }
[snip...]

...so i will always get a value passed to 'playerMove'. If it wasn't for you pointing me in the right direction i'd of been stuck on that for a while!

Thanks a lot! :)

Comment
Add comment · Share
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

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

No one has followed this question yet.

Related Questions

Why my rigid body with character controller is falling through ground? 4 Answers

object passes through floor 3 Answers

Checklist: Object or Character is falling through the floor 12 Answers

Collision with character controller and cube not working 1 Answer

Joystick movent and rotation on left joystick 0 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