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
1
Question by flosy · Oct 14, 2011 at 08:56 PM · charactercontrollergravity

Character Controller Gravity

Hi; I'm just wondering if there is a way to turn off the character controller gravity. Its causing my character to slip when walking up walls. I read some ware to change the Character Motor script but am unable to find any way to change the pre-set classes though. Any help would be appreciated (it is too late to change to a ridgidbody it would involve re-writing the entire game).

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Oct 14, 2011 at 09:36 PM

The CharacterMotor script is terribly complex: you can get completely crazy trying to modify it - I know, I was one of its victims... but in the madhouse I had time to create some tricks, like this function to set the gravity value:

function SetGravity(g: float){
    var chMotor: CharacterMotor = GetComponent(CharacterMotor);
    chMotor.movement.gravity = g;
}
Place this function in another script attached to the character, and use it to modify the gravity value (not the direction, unfortunately) when you need. In a few tests, this function effectively can turn the gravity off when you set it to 0. If the character is in the middle of a jump, for instance, it goes up forever unless you set the gravity to some reasonable value (default is 10).
Comment
Add comment · Show 3 · 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 flosy · Oct 14, 2011 at 10:15 PM 0
Share

I got Unity to accept the script but it gave me the errors "ArgumentException : You are not allowed to call GetComponent when declaring a variable." and another telling me the motor could not be found. I managed to get rid of the motor error by importing a character controller asset, it runs but I still get the "ArgumentException" error and it doesn't seem to work.

avatar image aldonaletto · Oct 14, 2011 at 10:54 PM 0
Share

Have you changed something? I tested this function, and it worked fine. This error could occur if you moved the first instruction outside the function: the variable would be public, and due to some reason that I ignore you can't declare a public variable and assign GetComponent to it in the same instruction - but you can use GetComponent in any instruction after. If you want to save ch$$anonymous$$otor in a public variable, do it this way:

var ch$$anonymous$$otor: Character$$anonymous$$otor;

function Start(){ ch$$anonymous$$otor = GetComponent(Character$$anonymous$$otor); }

function SetGravity(g: float){ ch$$anonymous$$otor.movement.gravity = g; } And remember that the script containing this code must be attached to the character (the First Person Controller, not a child of it!), or Character$$anonymous$$otor will not be found.

avatar image atomicjoe · Apr 29, 2013 at 05:33 PM 0
Share

This function doesn't work for me. It throws a null reference exception since the script can't find "ch$$anonymous$$otor" in the gameobject. Unity 4

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Help with Colliders? 0 Answers

Gravity and Jumping for a Character Controller 1 Answer

Character acceleration problem [Closed] 1 Answer

Character Flying around uncontrollably 2 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