• 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 Gerrit Jamerson · Dec 15, 2009 at 03:33 AM · physics

Using javascript to roll a ball... seems simple

Alright, I'm a complete newbie with Unity, and I thought you guys might be able to help.

At the moment, I'm making something along the lines of a small test game, where the player is able to control a ball or marble. I added a rigidbody to the ball, and when i started to script it, I ran into a dead-end.

At first I used rigidbody.AddForce() but it seemed unrealistic.

I tried to get it to move by using rigidbody.AddTorque(), but the ball doesnt seem to roll fast enough. I tried multiplying mainly, but no matter how high i put the numbers, the speed remained the same.

I cant find any other ways to do this. Is there something im missing?

Comment
Add comment · Show 1
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 iunity · May 19, 2012 at 10:14 AM 0
Share

hi,Gerrit

have done this feature? any example code can be show ? many thanks !

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Goody! · Dec 15, 2009 at 05:14 AM

If you are using the Iphone version of Unity you can check out the Unity demo Roll-A-Ball:

http://unity3d.com/support/resources/example-projects/iphone-examples

It's a simple roll-the-marble-past-the-holes type of game.

Even if you aren't using Iphone you may be able to pry some useful tidbits out of it. :)

--Goody!

Comment
Add comment · 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
3

Answer by Ashkan_gc · Dec 29, 2009 at 07:34 AM

rotation speed is limited by a setting in physics settings. just go to edit/project settings/physics and change the value of max angular velocity. don't set it to a really high value because it can produce errors. i use this code for rolling and it works well

if (rigidbody.velocity.magnitude < maxspeed) rigidbody.AddForce (Input.GetAxis ("Mouse X")*speed/ratio, 0, Input.GetAxis("Mouse Y")*speed);

i defined maxspeed, ratio and speed as variables in top of my code. i don't copy whole code because it's C# code and you don't use it. it has many other stuff too. the ratio variable is the ratio between z axis and x axis movements.

the movement is natural even with max angular velocity of 7 (default). don't change the value if you don't have to do so. it can result in a ball that pass other colliders.

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Finding the axis of a curving pipe 0 Answers

Manual collision check 2 Answers

Performance Question on Kinematic Rigidbodies 1 Answer

OnTrigger outside the trigger and collider gamobject 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