I feel the perform right here teleports the thing, for instance it must go from level a to level b and it does it by teleporting… you must optimize the perform by script.. as a substitute of teleporting, you must make it drag from level a to level b
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.Splines;
public class MoveAlongSpline : MonoBehaviour
{
public SplineContainer spline;
public float moveSpeed = 1f;
public float rotationSpeed = 5f;
non-public float currentDistance = 0f;
void Replace()
{
// Calculate the goal place on the spline
Vector3 targetPosition = spline.EvaluatePosition(currentDistance);
// Transfer the character in the direction of the goal place on the spline
remodel.place = Vector3.MoveTowards(remodel.place, targetPosition, moveSpeed * Time.deltaTime);
// Calculate the goal rotation on the spline
Vector3 targetDirection = spline.EvaluateTangent(currentDistance);
// Rotate the character in the direction of the goal rotation on the spline
if (targetDirection != Vector3.zero)
{
Quaternion targetRotation = Quaternion.LookRotation(targetDirection, remodel.up);
remodel.rotation = Quaternion.Slerp(remodel.rotation, targetRotation, rotationSpeed * Time.deltaTime);
}
// If the tip of the spline is reached, loop again to the start
if (currentDistance >= 1f)
{
currentDistance = 0f;
}
else
{
// Alter the motion based mostly on the size of the spline
float splineLength = spline.CalculateLength();
float motion = moveSpeed * Time.deltaTime / splineLength;
currentDistance += motion;
}
}
}