Hi,
I’d like to do a simulation of forces on bodies that sticks pretty closesly to reality (regarding physics). I calculate a Vector3 force and then want to apply it to a rigidbody.
This would be one possible solution:
using UnityEngine;
public class Showcase : MonoBehaviour
{
// both Rigidbody and force are given/calculated somwhere else
public Rigidbody body;
public Vector3 force;
// Update is called once per frame
void Update()
{
// F = m * a <=> a = F / m
Vector3 acceleration = force/body.mass;
// v = a * t
body.velocity += acceleration * Time.deltaTime;
}
}
However this directly messes with Rigidbody.velocity, which you should do according to docs (Unity - Scripting API: Rigidbody.velocity).
They point to Rigidbody.AddForce() but I have trouble using it: If I add a force, I don’t have any control on how long it will be applied. However this very important for realism, a force’s effect is proportional to the time it’s applied for.
What am I missing here? How can you steer for how long a force is applied with AddForce()?
Thanks a lot!!!