x


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?

more ▼

asked Dec 15, 2009 at 03:33 AM

Gerrit Jamerson gravatar image

Gerrit Jamerson
11 1 2 4

hi,Gerrit

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

May 19, 2012 at 10:14 AM iunity
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Dec 29, 2009 at 07:34 AM

Ashkan_gc gravatar image

Ashkan_gc
10.1k 77 101 164

(comments are locked)
10|3000 characters needed characters left

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!

more ▼

answered Dec 15, 2009 at 05:14 AM

Goody! gravatar image

Goody!
516 77 61 81

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x9236
x3182

asked: Dec 15, 2009 at 03:33 AM

Seen: 6339 times

Last Updated: May 19, 2012 at 10:14 AM