- Home /
Accelerate rigidbody by a specific value
I want to add a constant acceleration of 2 m/s^2 to my GO, but can't figure out how.
I already tried various Force modes, but don't really understand how exactly the force is added even after reading the documentation.
thanks in advance
Answer by sixShOOter50o0 · Jul 20, 2014 at 06:26 PM
I'm not that much of a professional programmer but you can use this script as an exaple of adding a specific acceleration:
var Acceleration : float = 2;
function FixedUpdate () //everything physics related is best if added in fixed update because it doesn't depend on framerate so you will have the same physics even with 30 fps and 300.
{
if (Input.GetKey ("w")) //you can put any key or button you want
{
rigidbody.AddForce (Vector3.forward * Acceleration);
}
}
Please note that adding force to a rigidbody will make you go faster and faster so you might want to make a speed limit.
Answer by NazeGames · Jul 20, 2014 at 06:38 PM
hi if I understand your problem (I'm pretty bad in English) but you would like to add a force of 2 every 2 seconds ... Have you tried this: //I don't know what is your language to code but it's an example in JS
var seconde : float;
var timeToPutForce : float;
var myForce : float;
function Update (){
seconde+=1*Time.deltaTime;
if ( seconde>=2){
seconde = 0;
myforce+=2;
}
rigidbody.AddForce(Vector3(0,0,myForce), ForceMode.Impulse);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613154545im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Confusion with AddForce with ForceMode.Acceleration 1 Answer
Physics object slides while turning. 1 Answer
How do i make the Impulse i give to my Player not be lowered by acceleration of gravity? 1 Answer
ForceMode.Acceleration 1 Answer
How to Tilt a Spaceship Based on Inertia/Acceleration Force Separate from Facing Direction? 2 Answers