- Home /
Instantiate Objects Along a curved (circulair) Path
Starting to learn coding I am trying to instantiate (or create) objects along a specific path. I found the code from " Arkham Interactive" helpful to create a Bezier curve. I can move an object along this path correctly but I am now tryring to instantiate objects along this path (using waypoints but trying to get them next to eachother). It works for the straight part but I cannot seem to get the correct angle at the sloped part. What I am trying to achieve is very similar to what has been shown in CatLike coding "Curves and Splines" (but this curve does not allows removal of points which make it hard to control). Does anyone have any ideas how (or guide me in the right direction) to instantiate (create) objects along a path consisting of waypoints (5 in this case but could be a random number) that has a curved shape and possibly have them all move around this path. I know the position of the waypoints (array) and I was testing to see if it would would be able to follow the curve using the code from Andeee (creating script for every two waypoints):
var startPoint: Vector3;
var endPoint: Vector3;
var numObjects: int;
var objects: Transform[];
function Start() {
for (i = 0; i < numObjects; i++) {
var newObj = Instantiate(objects[Random.Range(0, objects.Length)]);
newObj.position = Vector3.Lerp(startPoint, endPoint, (i * 1.0) / (numObjects - 1));
newObj.transform.LookAt(endPoint);
}
}
But this places the objects at a weird angle at the end of the waypoint (not using a symmetrical shape). I attah two images, the first one shows the original object in the red circle and the direction of the objects to be created (black arow). The blue arrow shows the results I would like to achieve but do not seem to be able. One aspect that I see is shown in the other image in the orange circle (assume it has something to do with the origen point but I am not sure). I understand that is most likely an easier problem to solve for experienced coders (which I a not) but any guidance is really appreciated. Thanks.
Your answer
Follow this Question
Related Questions
Problem with moving through waypoint 0 Answers
How to get an Object to move physically correct (velocity) 1 Answer
Object following the path 3 Answers
iTween nodes bug PLEASE HELP! 1 Answer