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 TheEmeraldRuby · May 11, 2018 at 02:22 PM · rotationrigidbodyaddforceaddtorque

How to make a ball capable of rolling around a loop the loop?

Hello to all. In my game, I want the ball player object to go around a loop the loop like a hotwheels car. I knew that rb.addForce() wouldn't work, since it pushes the ball in one direction corresponding to the key pressed, therefore just ending up pressing against the wall halfway up. Instead, I tried rb.addTorque, but I ran into a problem with that as well, since the different axis turn as the ball does. I think I'll have to make it so that the axis of the ball stays relative to the world, therefore guaranteeing that it will spin in the desired direction, but I have no idea how. If anyone knows or has a better solution, I would be very grateful. Thanks!

Comment
Add comment · Show 3
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 iJuan · May 14, 2018 at 06:53 PM 0
Share

By ball, you mean wheel or ball?

avatar image TheEmeraldRuby iJuan · May 15, 2018 at 04:56 PM 0
Share

A unity sphere @ijuan

avatar image iJuan iJuan · May 15, 2018 at 05:16 PM 0
Share

O$$anonymous$$, if I got it right, and you want to make a sphere rotate like a wheel steering to left or right, then you will need some physics.

Firstly you have to define a rotation radius, let's call it R

Next you have to define a point around which the ball will rotate. Assu$$anonymous$$g you are moving forward, that point will be (x+R, y, z) when turning right, and (x-R, y, z) when turning left (supposing x, y, z are the coordinates of the ball).

Now you have to apply a radial acceleration. This type of acceleration doesn't modifies the velocity of an object, but rotates it, and it's defined as |a|=v²/R

This means that you should define an acceleration magnitude, something like float mag = rigidbody.velocity.sqr$$anonymous$$agnitude / R;

Now you need the acceleration direction, which will always go from the ball to the point. Your resulting acceleration should be

 Vector3 acc = (point - transform.position);
 acc = acc / acc.magnitude * mag;

Next apply that force to the Rigidbody. (keep in count that this will only work if your ball's mass is 1kg. Otherwise, just mutilpy the acceleration by the ball's mass (in kg)

Now, if you apply this in each fixed update, your ball will rotate to the left (or right), and it's velocity won't be changed (linear drag, friction and other external forces may change your velocity, they probably will).

When you want your ball to accelerate or deaccelerate, simply modify it's velocity before calculating the radial acceleration (as it depends on the object's velocity)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Happeloy · May 11, 2018 at 02:51 PM

You could possibly try adding a force in the direction the ball is currently moving, that should work. You can access that direction from rb.velocity. I guess you should normalize the vector, so the amount of force added doesn't grow with the current speed.

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 TheEmeraldRuby · May 14, 2018 at 06:40 PM 0
Share

How would I do that? @Happeloy

avatar image Happeloy TheEmeraldRuby · May 15, 2018 at 05:16 PM 0
Share

Something like

 rb.AddForce(rb.velocity.normalized * force);

where force is a float with some value that gives you a good amount of push.

Though I have no idea if this will give you the behaviour you want, but it seems plausible, since the velocity vector will adjust an change each fixedupdate and should let you go around your loop. Though I don't think you should use this always, since it wont work if there is no velocity to start with.

avatar image iJuan Happeloy · May 15, 2018 at 05:19 PM 0
Share

That would just make sure the ball never stops moving, and that it keeps moving always on the last direction you ordered it to move

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

135 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 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 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 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 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 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 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

How to have a cube to fall on fixed rotation? 1 Answer

Prevent Rigidbody From Rotating 3 Answers

Rotating Camera, and Movement help. 1 Answer

Airplane goes weird on collision (Rigidbody) 1 Answer

Instantiating bullet and moving forward with rigidbody 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