Unity Move Along Path Spline Creator - Sebastian Lague

PHOTO EMBED

Wed Mar 10 2021 15:18:18 GMT+0000 (Coordinated Universal Time)

Saved by @cotterdev #c#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PathCreation; //<---- Don't forget


public class PlayerMovePath : MonoBehaviour
{
    //Variables
    [SerializeField] private PathCreator _pathCreator;
    [SerializeField] private float _speed = 5.0f;
    private float _distanceTravelled;
  

    // Update is called once per frame
    void Update()
    {
        _distanceTravelled += _speed * Time.deltaTime;
        transform.position = _pathCreator.path.GetPointAtDistance(_distanceTravelled);
        transform.rotation = _pathCreator.path.GetRotationAtDistance(_distanceTravelled);
    }
  
  	//This may also work, not proven yet
    void FixedUpdate()
    {
        _distanceTravelled += _speed * Time.fixedDeltaTime;
        _rb.MovePosition(_pathCreator.path.GetPointAtDistance(_distanceTravelled));
        _rb.MoveRotation(_pathCreator.path.GetRotationAtDistance(_distanceTravelled));
    }
}
content_copyCOPY