Sorry if my question is stupid (it probably is), but I am trying apply an impulse force on a ball (like it’s being hit by a racquet), so I thought the right thing to do was go with Forcemode.Impulse.
I am applying the force in FixedUpdate, and the force is applied all the time, so I don’t understand how Impulse is different from Force.
Shouldn’t an Impulse Force be applied just once and just stop when it meets another collider?
An impulse force is effectively the same as “Velocity = Velocity + Force * (1 / Mass)”
A non-impulse force effectively is the same as “Velocity = Velocity + Force * (1 / Mass) * SimulationTimeStep”
In other words, an impulse force isn’t time-integrated (scaled by the time-step being simulated) and you get all of the force applied to change the velocity. A non-impulse force is time-integrated so you only get a fraction of it.
The idea being that an impulse force is applied to get a fixed amount instantly irrelevant of the time-steps used for the simulation. A non-impulse force is time-integrated so you typically applied it continuously.
To hammer this home; if you apply a non-impulse force but before you apply it, scale the size of it up by the reciprocal of the time-step (typically 1.0f / Time.fixedDeltaTime) then it’ll be identical to an impulse force.
To be honest with you, I don’t understand most of what you are talking about here, the reason being that I am still kind of new to game physics and so far I haven’t been able to find even one good tutorial, official or unofficial, that goes over the subject in a clear and insightful manner.
So I will rephrase my question, using the most simple possible vocabulary and I would ask you to please try to reply keeping it as simple as possible:
When you hit a ball, you hit it just once and you apply only one force in just a fraction of a second. After you applied that force, the ball is gone and you have no way of applying any further force. I mean, you don’t follow up on the force you just applied. That’s how it works in real life.
So how can I do that in Unity?
Using AddForce in FixedUpdate is clearly not working, since the force continues to be applied forever.
So “hitting a ball once” is effectively the same as applying a single impulse force. Do it once, not continually again and again as that’s like following the ball and hitting again and again.
If you’re adding a force in FixedUpdate then you’re doing that again and again which is something you just said you didn’t want to do so don’t do that.
Maybe post some code if you’re still unsure? (Don’t forget to use code-tags if so).
It’s not about where you call it, it’s about calling it multiple times if you only want to call it once. I have not seen your code so I cannot see if you’re calling it again and again. All I can say is that FixedUpdate is obviously called continually so hopefully you have logic that ensures you’re not doing it each FixedUpdate.
Posting a code snippet might clarify what you’re doing.
Ok, I figured this out right after I submitted my last reply. What you point out is exactly the stupid mistake I was making. I put the line of code in FixedUpdate but right out there in the air, so it was effectively being called all the time.
Now I put the line inside an If Statement and it seems to work the right way.