public float jumpForce = 5f;
public float jumpIntervalMin = 1.5f;
public float jumpIntervalMax = 2.25f;
public bool IsCurrrentlyBeingGrabbed = false;
private Rigidbody rb;
private float jumpInterval;
private float timeSinceLastJump;
private int pp = 0;
private int Test = 0;
public bool TellToGrab = false;
private void Start()
{
rb = GetComponent<Rigidbody>();
SetNextJumpInterval();
}
private void Update()
{
timeSinceLastJump += Time.deltaTime;
if (timeSinceLastJump >= jumpInterval)
{
if (pp == 2)
{
pp = 0;
Turn();
}
else
{
Jump();
SetNextJumpInterval();
}
}
}
private void Jump()
{
rb.AddForce(Vector3.up * 5, ForceMode.Impulse);
StartCoroutine(PP());
pp++;
timeSinceLastJump = 0f;
}
IEnumerator PP()
{
yield return new WaitForSeconds(0.15f);
rb.AddForce(transform.forward * jumpForce, ForceMode.Impulse);
}
private void SetNextJumpInterval()
{
jumpInterval = Random.Range(jumpIntervalMin, jumpIntervalMax);
}
void Turn()
{
float randomAngle = Random.Range(-180f, 180f);
transform.Rotate(0f, randomAngle, 0f);
}