private void Update() { if (!isAnimating || currentSpeed == 0 || thisTransform.position == path[pathPointsCount - 1]) { return; } if (thisTransform.position != movingToPosition) { thisTransform.position = Vector3.MoveTowards(thisTransform.position, movingToPosition, currentSpeed * Time.deltaTime); pathRenderer.UpdateLastPathPoint(thisTransform.position); } else { movingToPositionIndex = Mathf.Clamp(++movingToPositionIndex, 0, pathPointsCount - 1); movingToPosition = path[movingToPositionIndex]; pathRenderer.AddPathPoint(thisTransform.position); } }
void FixedUpdate() { speed = Vector3.Distance(lastPos, transform.position) * 4f / Time.deltaTime; lastPos = transform.position; Debug.Log(Input.gyro.userAcceleration.normalized); if (speed > 0.001f) { lastPathPoint = pathRenderer.AddPathPoint(transform.position, speed * 10, lastPathPoint); } else { lastPathPoint = -1; } gameObject.GetComponent <Rigidbody>().AddRelativeForce( Input.gyro.userAcceleration.x * 1000f, 0f, Input.gyro.userAcceleration.z * 1000f ); }