- Home /
How to add aceleration to a sphere by pushing a key?
Hi everyone, I'm trying to make a javascript that move a ball by using aceleration when I push a key(not for mobile devices). Could anyone tell me how to do it or just give me the clue to think it by myself? Thanks :)
Answer by robertbu · Feb 20, 2013 at 10:31 PM
As mentioned above, you can use RigidBody.AddForce(). Typically the scripts I see on this list use AddForce() just once to (to shoot a projectile for example) and the object is up to speed. But your question asked about acceleration. If you want to cause something to speed up over time, you have to add a bit of force over a number of frames, rather than one explosive force. As an alternative, take a look at the Constant Force component (Component/Physics/Constant Force). In addition, if you are modeling anything that has a real world enlivenment, you will get best results from the physics engine if the size and mass of your object match the real world objects.
Answer by CGPHANT0M · Feb 20, 2013 at 12:11 AM
Rigidbody.addforce should do the job just fine.
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html
Check for key input:
if(input.getkey(keycode.uparrow)){} etc.
Then add the appropriate force to the transform. Vecter3.up etc.
Answer by Kiloblargh · Feb 20, 2013 at 12:15 AM
The developers of Unity could give you a clue, in fact they did : it's called the Scripting Reference. Have you read it?
Here are the first places you need to look:
Answer by albert_high · Feb 20, 2013 at 09:14 PM
Thanks both, and sorry for being so noob, yes i knew the scripting guide but you know, you have to know what to ask :S Tanks again :)
Your answer
Follow this Question
Related Questions
Move a ball using keybored 3 Answers
Fliping The Code Backwards? 1 Answer
Networking Accelerometer uses wrong axis 0 Answers
Rotating camera around the sphere 2 Answers