### Noob: Curves and snapping in Unity?

3646   2   1
Member
20 posts
Joined: May 2016
Offline
Hi all.
I want to be able to create curves in unity that are not at the surface.
For example If I have a building mesh prefab is there a method to place the curve on top of the mesh.
Any method to place curves on a different plane?
What I would really like to do is to create lofts similar to racing tracks but instead of laying it on the ground I could create the curves vertically to create an asset that lets me make 2.5D style levels.
Thanks
Member
176 posts
Joined: April 2009
Offline
Same here, would love to know if some sort of snapping is possible when creating curves in Unity. This could be very useful.
Member
184 posts
Joined: June 2010
Offline
You can add basic snapping yourself by editing HoudiniCurveGUI.cs

Look for two instances of new_point_location being set (search the first lines quoted below), and modify this value to snap:

Vector3 new_point_location = intersection;

// Grid Snap —————————————————-
new_point_location.x = Mathf.RoundToInt(new_point_location.x);
new_point_location.y = Mathf.RoundToInt(new_point_location.y);
new_point_location.z = Mathf.RoundToInt(new_point_location.z);
//—————————————————————

new_point_location = myCurve.transform.InverseTransformPoint( new_point_location );

// Grid Snap —————————————————-
new_point_location.x = Mathf.RoundToInt(new_point_location.x);
new_point_location.y = Mathf.RoundToInt(new_point_location.y);
new_point_location.z = Mathf.RoundToInt(new_point_location.z);
//—————————————————————

With snapping, it's easy to add points on top of points, so I'd suggest adding this after the second block above:

foreach (Vector3 p in myCurve.prPoints)
{
if (p == new_point_location)
return;
}

if (new_point_location == m_last_point_location)
return;

m_last_point_location = new_point_location;

You'll want to define Vector3 m_last_point_location as a private var, and give it a suitable quirky value like 99999.12345 so it doesn't stop you drawing in a valid place.

I'd add the complete code (with options and additional handles) for pull request submission, but I'm not that familiar with git. Wouldn't turn my nose up to looking at a guide/howto.

Projecting to a mesh (natively projecting the curve, and not i.e. via Ray SOP inside an HDA) should be do-able by i.e. raycasting into the scene (Unity's Raycast, not RAY SOP). Might need a bit more work putting it into practice as you're relying on Unity's collision precision, but it should work fine. But this level of customization is definitely better off in an RFE anyway.
Edited by AdamT - June 6, 2016 18:36:06