I have a kind of spikes in my game, where the sphere is "Player" if the player steps on the spikes it should be kicked out of the spikes collider. I'm using for now random range, it works well sometimes, but in some situations, it just comes to the spikes again. What I want is if the ball has collided with spikes it should be bounced away to a random position, but not be able to jump to the position of the spikes again, like a double collision.
public float ballBounceStrenght;
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.CompareTag("Player"))
{
Debug.Log("collision");
var position = new Vector3(Random.Range(-70, 70.0f), Random.Range(90f, 90.0f), Random.Range(-70.0f, 70.0f));
ball.AddForce(position * ballBounceStrenght);
}
}
This is the code I'm using run for random range. Have no Idea should I do it like that, maybe just fix numbers or there is some other way to do it.