Draw a path to follow

Hey guys I have been looking up ways to try to do something like this in Unity. Yet I still can’t figure out any methods. I would want to do this in game simply buy dragging while holding the left mouse button, then the object would follow the path drawn by the mouse.

I just need a starter on the making the path, getting the object to follow I can do myself. Take note that the game is 3D and so the path would be placed in 3D space.

Thanks guys.

you should break your problem into little parts.
I suggest you try to figure out how to paint on a texture. I believe you will find some stuff here in the forum.

Ill look into the painting on the textures, another question would be how stable instantiating and destroying empty game objects as reference points would be. Or would that just be a performance killer?

Hmm… I don’t know if you can create iTween paths on runtime… you should probably check that, and find a way to render the paths.

Ok so I made a line render do some stuff and I can draw on my scene in game. Next question is how can I clear what I have drawn? Atm it all stays there and I wand it to go away after I stop dragging my mouse. Is there a lineRenderer.clear or something? Or how would I accomplish that

This is what I have atm:

Code no longer available

bump

I got it to clear the last line but now, when you start a new one it always draws from the center, how do I fix that?

http://biochemicalink.net16.net/unity/testG/test.html

That is a webplayer, its built in the 3.5 beta. wasd to move q/e up and down. hold right click to move cam, note its a bit buggy cause of the beta stuff. if you click and drag the left mouse button you will see the line draw thing.

Another thing to note is that when the scene first starts, one piece of the line render is in the middle where your looking, then goes away on the first drag, how would that go away? (not very critical though). Mainly wanna know how to fix the fact it always starts form the middle after the first draw.

OK I solved this problem, I just cleared my list and set the count back to zero when I called the ClearLine function.

Hi,
If you still need an algo for the “follow path” part, let me try…

  1. When mouse is dragging, save mouse position (or a 3D pos given from a raycast) in a list during FixedUpdate (or in Update but not necessary every frame). Use the following method :
    a) Save your first point ‘p(0)’
    b) For each new point coming ‘p(x)’, calculate length : L = || p(x-1) - p(x) ||
    c) If L < minDistanceBetweenPoint then return, else save ‘p(x)’
  2. When mouse stop dragging save the last point 'p(n).

Now you have a list of target point.
To follow the target path, interpolate player position between each couple p(x), p(x+1) for x = 0 to x = n-1.
You can calculate the target rotation with operations on player orientation and vector [p(x)->p(x+1)], then slerp between current player rot to target rot.

Hope it helps.

P.-S. : The saving part has a drawback if the last point p(n) is to far from the p(n-1), because this is not tested…
P.-S. bis : I like math.