Beispiel #1
0
	void GenerateDefaultPath()
	{
		for (int i = 0; i < pathPoints.Count; i++) 
			pathPoints[i] = null;

		pathPoints.Clear();

		float radius = 3;
		CharacterPathPoint p1 = new CharacterPathPoint(new Vector3(-radius, 0, 0));
		CharacterPathPoint p2 = new CharacterPathPoint(new Vector3(0, 0, radius));
		CharacterPathPoint p3 = new CharacterPathPoint(new Vector3(radius, 0, 0));
		CharacterPathPoint p4 = new CharacterPathPoint(new Vector3(0, 0, -radius));

		pathPoints.Add(p1);
		pathPoints.Add(p2);
		pathPoints.Add(p3);
		pathPoints.Add(p4);
	}
Beispiel #2
0
	public Vector3 GetWorldPos(float pathPosition) 
	{
		// For non looping paths, clamp them to start and end 
		if (!looped) 
			pathPosition = Mathf.Clamp(pathPosition, 0, Max);

		pathPosition = pathPosition % pathPoints.Count;
		
		// Handle negative numbers so they arent out of range
		if (pathPosition < 0) 
			pathPosition = Max + pathPosition;

		int index = Mathf.FloorToInt(pathPosition);
		int endIndex = index + 1;
		if (endIndex >= pathPoints.Count) endIndex = 0;

		float progress = pathPosition % 1;
		
		CharacterPathPoint starting = pathPoints[index];
		CharacterPathPoint ending = pathPoints[endIndex];

		Vector3 pos = Vector3.Lerp(starting.pos, ending.pos, progress);
		return transform.TransformPoint(pos);
	}
Beispiel #3
0
	public void InsertNewPoint(int index, Vector3 worldPos)
	{
		CharacterPathPoint newPoint = new CharacterPathPoint();
		newPoint.pos = transform.InverseTransformPoint(worldPos);
		pathPoints.Insert(index, newPoint);
	}