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 Scorpox · Apr 10, 2013 at 04:32 PM · objectaxisballglobalxyz

Apply force from the object axis

Hi everyone, I'd like to know if there is any possible way of adding forces to a sphere from its own axis, I mean, when I apply the force it applies to the "global axis" and i want it to the objects axis.Here is part of my script, where I add the force to the ball:

 var ballVelocity=100;
 var dir : Vector3 = Vector3.zero;
         dir.x = Input.acceleration.x;
         dir.z = Input.acceleration.y;
         if (dir.sqrMagnitude > 1){
             dir.Normalize();
             dir *= Time.deltaTime;
             rigidbody.AddForce(dir * ballVelocity);
         }
 
Comment
Add comment · Show 2
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 Loius · Apr 10, 2013 at 04:39 PM 0
Share

if the ball is spinning in any way (for example, rolling around), its local axes are gonna be in a 'random' position every time you apply force, which would result in unpredictable behaviour.

an option that players might like would be applying forces from the camera's local axes, which are predictable and should make sense to the player. :)

look for 'unity camera relative movement' for the functions and stuff to convert directions from camera to world and back.

But if you do want local-axis forces, Fattie's got you covered.

avatar image Scorpox · Apr 10, 2013 at 04:43 PM 1
Share

Thanks for so quick responses :) That was the option i hoped will work well, but i didn't knew if it was possible. I see that it is... ;D Will this let me move a ball in the direction the cam is looking? Thanks again :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Fattie · Apr 10, 2013 at 04:33 PM

do you mean AddForceAt ?

or do you mean this ??

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddRelativeForce.html

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 Scorpox · Apr 10, 2013 at 04:52 PM 1
Share

Thank you very much Fattie, I'm pretty sure the second one is the one that i could use, but now I'd read about unity camera relative movement, I'd like to try both hehe ;D Thanks for the quick response :)

avatar image Fattie · Apr 11, 2013 at 04:24 AM 0
Share

HERE TO HELP !!

Could you please also read this very long answer and comments,

http://answers.unity3d.com/questions/418637/add-force-at-position-question.html

and you may like to, well, vote it up :) It's very helpful, I always liked that question but not many people read it. Note particularly the long comments at the end. CHEERS

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

Lerp a Object along X and Z axis only. 3 Answers

Tree position on random Terrain (y axis) 0 Answers

"Turn off" snapping of gameobjects inside editor? 5 Answers

Camera Following Spawned Object 2 Answers

Random ball generator? 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