Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 easilyBaffled · Jan 10, 2013 at 06:36 PM · rigidbodyaddforcerotatearound

Moving a ball through add force and rotate around

Stop be if you've heard this one before. I have a Rigidbody ball move along the outside of a tube. The script is pretty simple first pull the ball towards the tube, second add force to move the ball forward. Last get user input to rotate the ball around the tube. The problem is When the ball rotates around the tube too much too fast, the rotation gets out of whack and the ball goes flying into space. This is odd for a number of reasons, mostly because I have the balls rotation frozen in the Rigidbody inspector. Here's the script, can you help me?

 function FixedUpdate() {
     rigidbody.AddForce((-transform.up)*11);//Gravity 
     rigidbody.AddForce(transform.forward*5);//Forward
 
     Physics.Raycast(transform.position, -transform.up, hit, .5);//Begining of Turn
     rot = Input.GetAxis("Horizontal") * -10;
     
     if(rot != null && hit != null){
         Debug.DrawRay(hit.transform.position, (hit.transform.up), Color.white, 20);
         transform.RotateAround(hit.transform.position, Vector3.forward, rot);
     }
 }
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 robertbu · Jan 11, 2013 at 08:43 AM

Some suggestions.

Try upping the "Solver Iteration Count" (Edit/Project Settings/Physics). "Frozen" and/or "Locked" seems like more of a guideline to the physics engine in my limited experience, but upping the count helped me when I had frozen issues.

Limit the maximum velocity. In FixedUpdate() you can add something like:

 if (rigid_body.velocity.magnitude > 10.0f)
     rigid_body.velocity = rigid_body.velocity.normalized * 10.0f;

Given the regular nature of your geometry, you could even reposition your sphere and reset the velocity vector if the sphere goes out of bounds.

Or you could add an invisible tube with a collider so that the ball is really traveling between the inner tube and outer tube.

Comment
Add comment · Show 1 · 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 easilyBaffled · Jan 13, 2013 at 03:53 AM 0
Share

While I'm sure you're solution would have worked I actually figured out what the problem was, and still is, the ball is rolling on a curved tube right now, so the curve is forcing the ball to rotate around its z axis strangely. And when it did that the -transform.up, would pull it away so I've replaced that gravity with rigidbody.AddForce((tube.position-transform.position).normalized * 11); That seems to work but it is still rotating weird when I move it.

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

9 People are following this question.

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

Related Questions

How to move a rigidbody along a curve or spiral 0 Answers

Rotation problem with spawning bullet 2 Answers

Top Down car/vehicle movement 1 Answer

how get bow to add more force over time 0 Answers

How to make a ball capable of rolling around a loop the loop? 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