Move a object along a fixed path.
Hey guys me again. I am making a first person tower defense game. I have everything setup accept theres one problem; I have a path witch is pretty much a brown cube zig-zagging across the map. I would like to make a object move from the starting point to the end point of the map(And rotate accordingly, For exsample, if the path turnes). I thought about just using a animation and animating the position but it would be kinda wonky and i would like to add towers that slow/daze the enemy so that wouldnt work out to well. Any ideas?
So I don't know what your skill level is at but I would guess you are new to unity? I hate to say "You need to learn how to code it" but you kind of do.
What advice I can give is to learn how nav meshes work if you dont like that `you is you could easily make a 2D array that stores tower positions and also paths for enemies, each enemy could translate to each 2D index you set and once it gets there just get another index in the array for the enemy to translate to, repeat until they reach the end or some other spot.
So unless you know what I mean when I say 2D array, translate, index it's really hard to give an answer without telling you the entire process. Would you like me to explain it a little more?
Nah ive been using it a few years but i just couldnt think of a way to tackle this particular project. Ive decided to use a navmesh agent and just try to get it to not give me problems. But that gives me a new problem described here:
http://answers.unity3d.com/questions/1107452/navmesh-and-boxcolliders.html
Answer by Salanyel · Dec 04, 2015 at 10:54 AM
I may have an other solution for you : 1) Create a gameobject that contain all "Checkpoint" from the begin of the enmies spawn to the end of the map (For a cube, you'll have 1 at the beginning, 2 for the cube and 1 at the end). This gameobject contain all checkpoints in an array Like :
List<GameObject> m_paths = new List<GameObject>();
2) When you instantiate a new enemy, it gets the path saved in the scene. Then you use the method "MoveTo" with the coordinate of the first point.
3) When you reach the point, you go to the next one.
4) Remember to use a circle around the point. If you don't the enemy may just try to reach the exact point and bug at the same position.
Hope it helps you.
Is there a way to make then always go the same speed? The $$anonymous$$oveTo Command moves a distance in a set number of seconds. So if lets say path1s goal is 10 feet it will get there in 3 seconds. And if path2s goal is 50 feet it will get there in 20 seconds. See what i mean? Or am i totally wrong here?
I would use a constant speed http://docs.unity3d.com/ScriptReference/Transform.Translate.html
You can calculate a speed based on the distance between the two points in the path. When you reach a new checkpoint, you calculate the distance between the current point and the next checkpoint and calculate the speed based on the one you want. I don't have the formula under my hand, but I can give it to you later.
Answer by JusSumGuy · May 24, 2018 at 04:38 PM
I hate to say you need to learn code.... Sooo I wont. All you need to do is use the cinemachine. Under the cinemachine menu panel pick create a track. Then what ever object you want to move add a cart component to it. Assign the track to the cart. Then add points to your track and move them around to make your desired path. And on the cart option you can set the objects position on the track and the speed. And what do you know, no code needed. But learning calculus will make these things muchhhh more easier to the point where you'd be able to make your own waypoint system. So don't try to avoid learning code and math if you want to go far in this hobby/job/playground.
When I realized it was already to late :( . I felt the tingle of shame going down my spine.
Your answer
![](https://koobas.hobune.stream/wayback/20220612051326im_/https://answers.unity.com/themes/thub/images/avi.jpg)