// AutoMove creature in world public void AutoMove() { if (!isMovable) { return; } // Time update curTime += Time.deltaTime; // Check if creature should Stop if (currentDirection != 0 && curTime >= moveTime) { // This will reset movement if (isHop) { isHoping = false; lastColided = 0f; } currentDirection = 0; curTime = waitingTime; } // Keep in Limits GoBack(); // Move or Stop if (currentDirection != 0) { // Hop if (isHop && !isHoping) { // Generate a direction isGrounded = false; isHoping = true; shouldHop = true; jumpDir = CalculateWorldPosition(worldAngleDeg, jumpForce); } else if (isHop && isHoping && isGrounded) { isHoping = false; } } // Wait else { // If times up, check what to do next if (curTime >= waitingTime) { curTime = 0f; GenerateDirection(); isGoingBack = false; if (currentDirection == 0) { // for how long should it stay idle? waitingTime = Random.Range(1f, 5f); } else { // for how long should it move moveTime = Random.Range(2f, 5f); } } } attractor.Attract(creatureTransform, true); }
// Update is called once per frame void FixedUpdate() { attractor.Attract(bodyTransforms, true); }