Background:
I’m making prefabs for models that represent different parts of a street (straight, curved, 3 way intersection, 4 way intersection). With this I’m also including nodes on how cars can drive on the tile. Right now I’ve switched from manually placing a bunch of nodes to simulate a curve and instead defining tangent handles. Each node keeps a list of its neighbors that it can go to, and this “Neighbor” class contains the point, distance and tangent handles.
public class Neighbor
{
public WayPoint point;
public float distance;
public Vector3 handleStart;
public Vector3 handleEnd;
public Neighbor(WayPoint point) : this(point, point.transform.position, point.transform.position)
{
}
public Neighbor(WayPoint point, Vector3 handleStart, Vector3 handleEnd)
{
this.point = point;
this.distance = 0;
this.handleStart = handleStart;
this.handleEnd = handleEnd;
}
public void UpdateDistance(Vector3 from)
{
this.distance = Vector3.Distance(this.point.transform.position, from);
}
}
The problem:
My issue is that when making the prefab I’m entering the Vector3 positions of each handle, but then upon rotating the prefab its not also rotating where the handle should be so my curves are getting all messed up.
0 Degree Rotation (correct)
90 Degree Rotation (incorrect)
Question:
My thinking is that I may have to check the rotation of the prefab and figure out some calculation to get the proper rotation, but at the same time I feel like there has to be something Unity already has to do this (since it does it for other things such as the node gameobjects). Another option is I could create gameobjects for each handle but this seems excessive. Is there anyway to tell unity that a Vector3 is relative to the gameobject and not the world space?