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 TrojanFM · Mar 01, 2012 at 08:27 AM · javascriptcharactercontrollergravity

Change the gravity direction for CharacterController

like what the title says .. i have a CharacterController .. i made a code to change the rotation of the player so he would look like walking on the roof .. but he's walking on the floor upside down .. how can i change the gravity ?

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
0

Answer by Madeck · Dec 12, 2014 at 08:45 PM

If you have a CharacterController and you want to change the gravity, you have to access the component’s CharacterMotor.movement.gravity variable and change it. By default the CharacterController will only work with positive and negative gravity, you will have to build something different if you want to have complete control over gravity direction rather than simply switching its direction along the y axis.

I built my gravity inverted, I had to make sure to set CharacterMotor.grounded = false in order for the character not to be stuck on the roof.

I know your question is over two years old, but in case someone has a similar one someday, they might find this answer helpful.

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 robotzStudio · Dec 12, 2014 at 08:52 PM 0
Share

Add C# code example please!

avatar image Madeck · Dec 12, 2014 at 11:28 PM 0
Share

I usually script in UnityScript, but here’s what I basically do–except I added a short animation to make it smoother:

 void OnTriggerEnter (Collider other) {
     
     if(other.tag == "Player") {
         other.transform.Rotate(0,0,180);
         Character$$anonymous$$otor.grounded = false;
         Character$$anonymous$$otor.movement.gravity *= -1f;
     }
 }

Just for your information, there are several problems that arise when you’re using inverted gravity, as the Character$$anonymous$$otor is never “grounded” when it’s on a roof. I’ll probably post some more information if I figure out properly how to make everything work fine, especially with slopes or stairs.

avatar image Sean__R · Nov 04, 2015 at 12:13 PM 0
Share

Thank you, $$anonymous$$adeck. I think this is what I needed.

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

6 People are following this question.

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

Related Questions

Gravity with Character Controller? 4 Answers

Double Jump 1 Answer

A node in a childnode? 1 Answer

Collision Detection 0 Answers

if CharacterController hit a rigidbody 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