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 ducsuus · Mar 01, 2014 at 10:30 PM · rotationpositiongravityvector

How to set and objects gravity direction to Z -10 based on the objects rotation? (2D)

Recently I have been working on a 2D mind-fuzzle game, which more or less turns everything inside out with interesting and intuitive ideas, I can tell you now, if you get motion sickness you won't like this game :P

Anyway, I have been playing around, and I would like the controls of the game to be simple, move the character left and right, and change the characters gravity by pressing space to a vector of (0, -10, 0) or something like that. I have been using (0, -1, 0) for debug purposes.

This vector, however, needs to be based on the players rotation. If I where to move my player of the side of a roof, it would start to rotate half way off the side of the roof, pressing space would then change the players gravity to (0, -10, 0) based on the players rotation, not the static coords.

Here is a picture to explain what I want to do. The left shows the player rotated with the gravity (0, -10, 0) as a vector from the players position, rotation is not considered. The right shows what I want, the gravity as (0, -10, 0) based on the players position AND rotation.

alt text

Could someone please help me do this? If I have not been clear enough please ask me, I have made a decent effort to try and get this working :S

Thanks in advance,

~Joe

unityexample.png (48.5 kB)
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 robertbu · Mar 01, 2014 at 10:33 PM

Untested but try this:

  Physics2D.gravity = -transform.up * gravityAmount;

This will have to be set when your character is rotated. I don't know the nature of your game, but it will effect all the objects in the scene.

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 ducsuus · Mar 01, 2014 at 10:38 PM 0
Share

@robertbu, I am sure the custom gravity would work, but I would prefer to use the built in gravity.

I hate to contradict but I think you can modify the built-in gravity. If I used this line of code:

 Physics2D.gravity = Vector3(0, 10, 0);


Every time I pressed space, I would be able to "invert" gravity. It works fine for me, but I want this Vector to be based around the players rotation.

avatar image robertbu · Mar 01, 2014 at 11:16 PM 0
Share

@ducsuus - Don't hesitate to correct me, and you are right. I'll edit my answer. I based my answer on what was exposed in the Inspector and did not take the time to read the reference.

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

Unable to set Rotation 1 Answer

Converting www.text or string to rotation or position 2 Answers

Calculating a new position based on where another object is facing 1 Answer

Add an offset to the position of an object in front of it 1 Answer

How can I identify a non-uniform scaled mesh, and fix it? 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