I want my gameobjects to fall faster as the time goes. Gameobject falling is getting called when the player collides with if.
Here’s my code:
private Rigidbody rb;
public float currentFallDelay = 1f;
float minFallDelay = 0.3f;
public float accelerationTime = 60;
private float maxFallDelay;
private float time;
void Start()
{
rb = GetComponent<Rigidbody>();
minFallDelay = currentFallDelay;
time = 0;
}
public void FallDelay()
{
rb.isKinematic = true;
currentFallDelay = Mathf.SmoothStep(minFallDelay, maxFallDelay, time / accelerationTime);
transform.position += Vector3.down * currentFallDelay * Time.deltaTime;
time += Time.deltaTime;
}
void OnCollisionEnter(Collision col)
{
if(rb.isKinematic && col.collider.CompareTag("Player"))
{
FallDelay();
}
}
What am I doing wrong?
All helps are appreciated!