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 Coreyf716 · Dec 16, 2012 at 08:07 PM · javascriptvector3charactercontrollermove

CharacterController Gravity

CharacterController.Move sets isGrounded to false. 1) Why? 2) With this code, if the player has been moving, their gravity begins to build up. When the player falls, they fall at a very high velocity. I tried using raycast to check if the player was actually grounded, but it didn't turn out working well.

 #pragma strict
 
 public var player : CharacterController;
 public var gravity : float;
 public var grav : Vector3;
 
 function Update() {
     if (!player.isGrounded) {
         grav.y -= gravity * Time.deltaTime;
         player.Move(grav * Time.deltaTime);
     } else {
         grav = Vector3(0, 0, 0);
     }
 }
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 Dexter.Unity · Dec 16, 2012 at 08:36 PM 0
Share

So if your player is not grounded, you want him to fall by gravity, but slow the influence of gravity down (with you float value) the longer he is in the air ?

avatar image Coreyf716 · Dec 16, 2012 at 08:46 PM 0
Share

no. As the player moves, gravity increases. I don't want it to do that.

avatar image Dexter.Unity · Dec 16, 2012 at 08:53 PM 1
Share

Try to change the - in +:

grav.y (-)(+)= gravity * Time.deltaTime;

And it's still not very clear what the behavior of the character should be: "When he is in the air he should fall down linear?" Or "When he is in the air he should fall down but not so fast as gravity will make him fall?" Or "When he is in the air he should fall down like gravity want's it to but with a maximum fall speed, so when he falls down faster than 2m/s it should sray that velocity?"

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by cumhuryozcan · Dec 16, 2012 at 11:35 PM

As for the second question, change the line

 grav.y -= gravity * Time.deltaTime;

to

 grav.y = -gravity * Time.deltaTime;

In other words, delete minus sign before the equals sign and put it next to gravity. This will solve the "falling too fast" problem. What you do wrong was increasing the gravity effect every frame. After a few frames (in less than a second) your gravity reaches an extremely large value and this causes the player to move too fast. Then delete the else part as you wouldn't need it. I also believe that you do not need to multiply the value with Time.deltaTime two times so you may want to delete one of them.

For the first question, I don't believe that it is the Move method of the CharacterController directly causes the isGrouded to be false. What I suspect is, when you change the player's position (via Move), player actually becomes un-grounded. So I think the problem is actually about design of your scene.

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

Answer by Nirav-Madhani · Mar 22, 2015 at 03:26 PM

well , when its about Gravity ,Character Controller has it already and you just need to trigger it Something Like This

  var controller : CharacterController = GetComponent(CharacterController);
 controller.SimpleMove(Vector3 .forward * 0);
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

12 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

Related Questions

Respawn when a character hits an object with a tag of "Kill" , but after 3 deaths the controller is destroyed 0 Answers

when i try using .SimpleMove my object jumps back to its starting position 0 Answers

Vector3.lerp doesn't work 1 Answer

Move empty object random 1 Answer

CharacterController.Move precision 1 Answer


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