I’m trying to make a cube (cart placeholder) follow along a track:
I’m wondering what the best method is to achieve this. A pathing system like Spline Controller will not suffice because I don’t want to have to configure the waypoints on the track; it should just follow it. I was thinking of creating the script like so;
- Set the target track object
- Position the host object in the middle of the track object
- Keep raycasting diagonally downwards from the top-front of the cube to see if there’s still a track in front of it
- Move forward if so
- Optionally have the cart/cube reverse direction if the track ends, in case it doesn’t loop
- Optionally create the path once at script startup rather than dynamically in case the track is static
Would this work, and would it be o.k. performance wise (in other words; is there a better alternative, performance wise)? Also, what do I need to look in to to make the cart/cube turn across curves so it doesn’t end up looking silly?