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 rednax20 · Apr 21, 2014 at 10:37 PM · charactercontrollergetcomponentfalling

strange character controller falling

this one is a bit odd. I'm new to character controllers so i have no idea what is happening I wrote a script but i don't really think you'll need it to understand my problem.

notice i use simple move to move my character around, it works great until he falls off the edge of a platform.

the character sometimes falls off normally, but other times he falls super far, around three times as far to be exact!

i can't explain it, but i know that i cant have that happening all help is apprecieated

here's my script, again i won't think you'll need it (i only stress that because i never read peoples questions who barf 100 lines of code)

 var movespeed = 30;
 var airtime = -1; // used to find out how much longer to lerp
 var jumphieght = 10;//just in case we add like a "high jump boots item;
 var jumptohieght = 0; //the hieght to jump from which they are right now
 var controller : CharacterController;
 controller = GetComponent(CharacterController);
 function Update () {
 //simple movement
 
         if(Input.GetKey(upkey)){
             controller.SimpleMove(transform.forward *  movespeed * Time.deltaTime);
         
         }
         else if(Input.GetKey(downkey)){
         
             controller.SimpleMove(-transform.forward *  movespeed * Time.deltaTime);
         
         }else{
         
             controller.SimpleMove(Vector3(0,0,0));
 
         
         }
         if(Input.GetKey(rightkey)){
          
             transform.Rotate(0,120 * Time.deltaTime,0);
         
         }
         if(Input.GetKey(leftkey)){
          
             transform.Rotate(0,-120 * Time.deltaTime,0);
         
         }
         if(Input.GetKeyDown(jumpkey) && controller.isGrounded == true){
             airtime = 10 ;
             jumptohieght = jumphieght + transform.position.y;
             
         }
 
     if(airtime >= 0){
     airtime += -1;
     
     transform.position.y =   Mathf.Lerp(transform.position.y, jumptohieght, 0.1);
     
     }
 }
Comment
Add comment · Show 7
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 rednax20 · Apr 22, 2014 at 01:20 AM 0
Share

oh yeah, i forgot to mention, the jumping works like that too. sometimes i jump really far, and other times not as far.

hope this helps

avatar image getyour411 · Apr 22, 2014 at 02:01 AM 0
Share

This is off topic but to save you potential headaches down the road if you try to get a variableHeight from this script, you've transposed the i and e in height in every case (height vs hieght). $$anonymous$$y guess is the issue is the $$anonymous$$athf.Lerp but I couldn't say for sure.

avatar image rednax20 · Apr 22, 2014 at 02:04 AM 0
Share

thanks, actually i do that because it allows me to type faster

I used to type fo r ward as foward, that's just how i did it. i will be sure to change that if it becomes a problem. i love mono developes find tool

avatar image rednax20 · Apr 24, 2014 at 01:13 AM 0
Share

is some other games I've played (albeit they weren't made in unity), I've come across this sort of problem in playing them. is this an unavoidable issue?

avatar image getyour411 · Apr 24, 2014 at 01:17 AM 0
Share

I don't understand the premise - clarify what you mean by 'the players falls three times as far'. Did you mean falls three times as fast?

Show more comments

1 Reply

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

Answer by rednax20 · Apr 28, 2014 at 07:35 PM

i figured it out, so i'll post the answer here for anyone else who happens to have this problem (which it sincerely surprises me that i haven't seen anyone else with this problem around the web.

my problem was on line 11

 controller.SimpleMove(transform.forward *  movespeed * Time.deltaTime);

this essentially moves the character forward. Time.deltaTime is used to make everything move at a uniform rate on all computers.

It does't make the rate uniform, but rather, moves the controller faster when the frames are longer. But, if the character jumps or falls of a ledge, physics take over. the physics will move the character at a good speed from the very last point he moved (in this case the moment before he jumped or fell).

this means that if the frames speed up or slow down the character will move faster or slower than normal for just an instant, but if that instant is right before when you jump or fall you will keep that speed for the duration of the fall, so you could go really far or hardly move at all.

So I can't use Time.deltaTime

to resolve this all i had to do is put the code in a fixed update, where things will move in at a fixed rate and increasing speed will not be necessary

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help! Problems with Character.isGrounded in Unity 4.0.1? 3 Answers

Moving Platform and CharacterController.Move not working. The player falls 3 Answers

Character collider / physics bug in Unity 3.3 - falling through terrain / objects 5 Answers

Turn off CharacterControl Component Through Script? 1 Answer

Animation through graphics in FPS controller, weird character controller issue, NEED help! 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