I’m making a runner where the speed should vary a little so that the character’s not always on the same point, and I’m having troubles with the Clamp function.
I searched for it and came across another question about it here, where the answer was something similar to what I’m doing, but it doesn’t work for me.
This is my code
private float boost = 1;
private float acc = 0;
void Update(){
acc = Mathf.Clamp(acc, -boost, boost);
print (acc);
rigidbody2D.velocity = new Vector2(acc, 0f);
}
I’m printing the acc value and the only number I’m getting is 0, which is its initial value.
Please I need help with this function couse it’s driving me mad.
Thanks in advance.