Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ryanbuddy1 · Jul 14, 2011 at 05:56 PM · physicsobjectcharacterrotategravity

Rotate Gravity 90 degrees for one object.

How do I rotate a player character's gravity 90 degrees on button press? An example of what I want it to do is when you press page down, the gravity of ONE object / character only rotates 90 degrees clockwise. I have tried almost every possible way to get it to work. Please help ASAP. Below is what I currently have as a script that is attached to the character:

 var forceToAdd : Vector3 = Vector3(5,5,0);
 var obj:GameObject;
 private var other:RotateObject;
 var rotating : boolean = false;
 var changegravityminus :boolean = false;
 var changegravityplus :boolean = false;
 
 function Start() {
     other = obj.GetComponent(RotateObject);
 }
 
 function Update () {
     if (other.gravity == 1){
         transform.Rotate (0,0,0);
         rigidbody.AddForce (0, 0, 0);
         Physics.gravity = new
         Vector3(0f,-9.81f,0f);
     }
     
     if (other.gravity == 2){
         transform.Rotate (0,0,90);
         rigidbody.AddForce (0, 0, 0);
         Physics.gravity = new
         Vector3(-9.81f,0f,0f);
     }
     
     if (other.gravity == 3){
         transform.Rotate (0,0,90);
         rigidbody.AddForce (0, 0, 0);
         Physics.gravity = new
         Vector3(0f,9.81f,0f);
     }
     
     if (other.gravity == 4){
         transform.Rotate (0,0,90);
         rigidbody.AddForce (0, 0, 0);
         Physics.gravity = new
         Vector3(9.81f,0f,0f);
     }
     
     
     if(Input.GetKeyDown (KeyCode.PageUp)&& rotating==false){
         changegravityminus=false;
         rotating=true;
         transform.Rotate (0,0,-90);
         rigidbody.velocity = forceToAdd;
         Physics.gravity =Quaternion.Euler(0, 0, -90) * Physics.gravity;
         rotating=false;
         changegravityminus=true;
     }
     
     if(Input.GetKeyDown (KeyCode.PageDown)&& rotating==false) {
     rotating=true;
     transform.Rotate (0,0,90);
     rigidbody.velocity = forceToAdd;
     Physics.gravity =Quaternion.Euler(0, 0, 90) * Physics.gravity;
     rotating=false;
     }
 }
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
Best Answer

Answer by Chris D · Jul 14, 2011 at 06:43 PM

 if(Input.GetKeyDown("Fire1")){
     yourDifferentGravityGO.rigidbody.useGravity = false;
 
     //a flag to refer to in fixed update so you can change it's behaviour
     yourDifferentGravityGO.isGravityDifferent = true;
 
     //then apply a constant force in Fixed Update in the direction you want
 }

Turn the default gravity off, apply a constant force.

Comment
Add comment · Show 2 · 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 ryanbuddy1 · Jul 14, 2011 at 08:19 PM 0
Share

Sir you deserve a medal, thank you.

avatar image Chris D · Jul 14, 2011 at 08:21 PM 1
Share

Glad it helped; good luck!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Player flies up into the air when walking 3 Answers

character gravity problem 1 Answer

Gravity only rigidbody 1 Answer

Rigid Character always falls (Physics) (No Root Motion) 1 Answer

How to change gravity direction on Character Motor 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