Newer
Older
CGTrack / Assets / Scripts / CartFollower.cs
@Pascal Syma Pascal Syma on 25 Jul 2021 818 bytes Initial Commit
using System;
using System.Collections;
using System.Collections.Generic;
using DefaultNamespace;
using UnityEngine;

public class CartFollower : MonoBehaviour, ICart
{
    public GameObject _cart = null;
    private ICart cart = null;
    public float distance = 10.0f;
    
    public float u = 0;

    private void Awake()
    {
        cart = _cart.GetComponent<ICart>();
    }

    private void Update()
    {
        if (cart == null)
        {
            return;
        }

        u = cart.getU() - distance;
        
        u = getTrack().GetPositionOnTrack(u, out var pos, out var rot, out var a);

        transform.position = pos;
        transform.rotation = rot;
    }

    public float getU()
    {
        return u;
    }

    public Track getTrack()
    {
        return cart.getTrack();
    }
}