Why my 2D sprite will leave a trace in the canvas?
if (waypoints == null || waypoints.Length == 0) return; Transform targetWaypoint = waypoints[currentWaypointIndex]; Vector2 direction = (targetWaypoint.position – transform.position).normalized; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; Quaternion targetRotation = Quaternion.Euler(new Vector3(0, 0, angle)); transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime); rb.MovePosition(rb.position + direction * speed * Time.deltaTime); if (Vector2.Distance(transform.position, targetWaypoint.position) < 0.1f) { currentWaypointIndex++; if […]
Why my 2D sprite will leave a trace in the canvas?
if (waypoints == null || waypoints.Length == 0) return; Transform targetWaypoint = waypoints[currentWaypointIndex]; Vector2 direction = (targetWaypoint.position – transform.position).normalized; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; Quaternion targetRotation = Quaternion.Euler(new Vector3(0, 0, angle)); transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime); rb.MovePosition(rb.position + direction * speed * Time.deltaTime); if (Vector2.Distance(transform.position, targetWaypoint.position) < 0.1f) { currentWaypointIndex++; if […]
Why my 2D sprite will leave a trace in the canvas?
if (waypoints == null || waypoints.Length == 0) return; Transform targetWaypoint = waypoints[currentWaypointIndex]; Vector2 direction = (targetWaypoint.position – transform.position).normalized; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; Quaternion targetRotation = Quaternion.Euler(new Vector3(0, 0, angle)); transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime); rb.MovePosition(rb.position + direction * speed * Time.deltaTime); if (Vector2.Distance(transform.position, targetWaypoint.position) < 0.1f) { currentWaypointIndex++; if […]