Question by
Nagamorii · Mar 21, 2019 at 02:28 AM ·
scripting problemscripting beginner
rb.addforce question
how can i continually adding force to my player every second? Even if i put the script into void Update instead of Void FixedUpdate the velocity remains the same.
void Update()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
}
Comment
You will have to be more precise. Do you want your object to get an "impulse" force every second ? $$anonymous$$eaning your object will accelerate when t=0
, then decelerate before the next impulse at t=1
?
If so:
float timer = 0;
float impulseInterval = 1;
void FixedUpdate()
{
if( timer < $$anonymous$$athf.epsilon )
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
timer += impulseInterval;
}
timer -= Time.fixedDeltaTime;
}