bansheeGz / BGCurve

Bezier spline editor for Unity game engine
MIT License
142 stars 27 forks source link

Spawn GameObject along point of curve? #12

Closed SpicyTunaRoller closed 6 years ago

SpicyTunaRoller commented 6 years ago

Hi BG!

So I am using your asset (great job!) and I think it would be a good improvement to allow instantiating gameobjects along the curve. I want to try implement this, but am not sure where to start. Can you please point me in the right direction?

I would think it would be broken into 2 parts;

  1. Add a new Green Component field, something like Spawn Gameobject Along Curve, with a field for the gameobject, and a minimum distance to find the nearest point to spawn it on. If its further than this, create its own point to spawn from.

  2. With Ctrl held along spline point, Right Click to spawn at nearest point.

If this sounds reasonable, please let me know where I should start! Thank you!

banshee-gzzz commented 6 years ago

Hi, SpicyTunaRoller!

If you need this exact algorithm, you described (with minimum distance etc.), you have to edit Editor classes (classes, located at Assets\BansheeGz\BGCurve\Scripts\Editor). Honestly, I do not know if it's a hard task or trivial one. Anyway, you will have to figure out how these classes work and add your own logic.

But if you only need to place objects along the curve, this can be done like this: 1) add "Translate Object By Cursor" component to the curve (it will create Cursor component as well) 2) Set Cursor to the desired position. 3) Drag component you want to place to Translate's component ObjectToManipulate field. 4) The object will be placed at cursor's position. You can move the cursor to adjust the position. As soon as the object is placed, clear ObjectToManipulate field (or assign next object to move) 5) as soon as all objects are placed, remove Translate and Cursor components

SpicyTunaRoller commented 6 years ago

Oh! Thank you so much BG!

Your method works well! A lot simpler than I was thinking :).

Closed and Solved!