Linear Acceleration in unity 3d?

Hi Guys… Please check this link and tell me the correct answer.

In above application how can i provide same linear acceleration in unity 3d?
i followed Unity - Scripting API: Input.acceleration
this link but ball can’t move… there is no change in object(sphere/ball) position. In this script i am getting dir=(0,0,0) so that i think ball can’t moving… please tell me the way how to do that.

Thanks to all my viewers.

Well, linear acceleration is easy enough if you understand the physics behind it. Let’s think first in scalar values and then this will be easily translated into vectors. First of all, acceleration is measured in distance over square time (m/s^2 in the metric system), and that means, a “meter per second” per second, so each second, you increase your speed by that amount. So, to implement a linear acceleration to an object in Unity, you can work easily with some basic equations and 3d Vectors to get the very same effect.

Your object has an speed vector, this vector has the direction and magnitude of its speed, the initial value for that vector should be, thus, your initial speed. Then, you might want to apply an acceleration to that vector, it’s as easy as adding each frame a fixed value to that vector, in the direction you wish to have the acceleration. A common case for that is gravity, if you apply a constant acceleration downwards, you’ll have a realistic gravity motion.

That’s the problem, of course, of a frame not being a fixed amount of time, and that is solved with the class member Time.deltaTime, you can check out why does it work on the documentation, but basically multiplying your acceleration (and also speed) Vector by Time.deltaTime, you’re translating the amounts in meters/frame to meters/second, which is a fixed amount of time. If you don’t do that you’ll have your character moving at different speeds on different computers, and even on the same computer the speed may vary on the CPU consume, which you definetly don’t want.

Also, to a more specific implementation, if you’re new to Unity, each object’s position is stored in a Vector3 at its transform.position member (you can call this from whithin any monobehaviour script), modifying this vector over time will result in motion.

Hope it helped!

If you want to create acceleration use:


Using the default one will not do as forces will get added each frame resulting in warp speed within a few second. A simple script like this should get you started:

public class Script : MonoBehaviour {
	Rigidbody rig;
	float move;
	float speed = 70;
	void Start () {
		rig = GetComponent<Rigidbody>();
		gameObject.renderer.material.color =;
	void Update(){
		move = Input.GetAxis("Vertical");
	void FixedUpdate () {
		print (rig.velocity.magnitude);
		if(move != 0)

This will get your object moving like a really simplified car.

That is really helped me a lot… please give me one more clarification on that how will i provide arrows of velocity and acceleration like same link in play mode ?

If you want to visualize an acceleration vector, use the LinearAcceleration() function here:

and then use Debug.DrawRay() to draw a line made from the output vector.