|
I am new at Unity and I have been trying to make a code for a game similar to super monkey ball or marble blast gold. The problem is that the code I am using isn't working. Can someone please help. Here is my code.
(comments are locked)
|
|
There are several possibilities here. One could be that the applied force is too small another one could be that you apply the force to the wrong rigidBody or you don't even receive the keyboard input. Try the following: if you don't get a message in the console, you know that the keyboard never "arrives" correctly. If you get a message just increase 10 to 1000 or something way bigger. Trial and Error: just eliminate different possible error sources one after another.
(comments are locked)
|
|
To roll a ball, I recommend AddTorque (I.e. spin it) and let friction do the work. Otherwise you get unnatural effects, like in-air acceleration. For playability, a combination may be needed. It says NullReferenceException Object Reference not set to an instance of an object.
Aug 14 '11 at 02:47 PM
890evil
Don't you think you should edit your Question with that vital information? Way more intelligent and informative than "isn't working".
Aug 14 '11 at 02:51 PM
Waz
(comments are locked)
|
|
Oh, I see one of the problems. You have spelt Forward incorrectly. It is Forward, not foward. Also, there is no Backward in unity. You have to instead use forward but the negative of it. For example:
(comments are locked)
|
|
The problem is you forgot to put in the {}'s. Wrong Way: if (Input.GetKey ("down")) rigidbody.AddForce (Vector3.backward * 10); ... Right Way: if (Input.GetKey ("down")) { rigidbody.AddForce (Vector3.backward * 10); } No, that format works. It's not the prettiest, or the safest, but it is legal code.
Oct 07 '11 at 04:07 PM
syclamoth
Oh does it? Wow, I guess I learnt something new. I tried that a few months ago and it didn't work. (Must have stuffed up somewhere else). Thanks for the heads up.
Oct 07 '11 at 04:22 PM
djfluffwug
it works, but it's still not good to use.
Oct 07 '11 at 04:35 PM
syclamoth
(comments are locked)
|
|
Never use the addForce and addTorque, basically anything that has to do with the physics on update. You must applythem on FixedUpdate
(comments are locked)
|
