Rusty on my Calc...

alright, so I want to place a few Vector3 along a path between two known points, but I want to smooth them out a bit.

How can I use Sin in this function to offset the vertices? As it sits, it will place them in a straight line…

Vector3[] SmoothVerts(Vector3 first, Vector3 second){
		Vector3[] tempArrayVerts = new Vector3[unitsUP];
		for (int i = 0; i < unitsUP; i++) {
			tempArrayVerts _= new Vector3	(((first.x-second.x)/units)*i-first.x,_

_ ((first.y-second.y)/units)*i-first.y,_
_ ((first.z-second.z)/units)*i-first.z);_

  •  }*
    
  •  return tempArrayVerts;*
    
  • }*
    Maybe this will help. I made an image to show what I am trying to accomplish… point of inflection is at the Mean of the two vertices. The distance from the Mean to the Origin determines the relative value of x.
    [9770-sine.jpg|9770]*

Here is a bit of code that will produce a set of point in a serpentine line. In order to figure out how to move the points from the line, you need to figure out the plane you want the points confined to. You need two vectors. One will the the line itself. The code below arbitrarily picks Vector3.up for the second. Vector3.Cross() will produce the vector for the back and forth movement.

Attach this code to an empty game object and hit play:

public class Serpentine : MonoBehaviour {
	
	public int points = 500;
	public float scale = 0.5f;
	public float speed = 0.1f;
	public Vector3 v3Start = new Vector3(-4.0f, -1.0f, -4.0f);
	public Vector3 v3End   = new Vector3(4.0f, 3.0f, 5.0f);
	
	private Vector3[] arv3Points; 

	void Start () {
		arv3Points = new Vector3[points];
		Vector3 v3 = Vector3.Cross (v3End - v3Start, Vector3.up);
		v3.Normalize ();
		
		for (int i = 0; i < arv3Points.Length; i++) {
			Vector3 v3Curr = Vector3.Lerp (v3Start, v3End, (float)i / ((float)arv3Points.Length - 1.0f));
			arv3Points _= v3Curr + v3 * Mathf.Sin ((float)i * speed) * scale;_
  •  }*
    
  •  // Generate some spheres to visualize the points*
    
  •  Vector3 v3Scale = new Vector3(0.2f, 0.2f, 0.2f);*
    
  •  for (int i = 0; i < arv3Points.Length; i++) {*
    
  •  	GameObject go = GameObject.CreatePrimitive (PrimitiveType.Sphere);*
    
  •  	go.transform.localScale = v3Scale;*
    

_ go.transform.position = arv3Points*;_
_
}_
_
}_
_
}_
_If you need your curve to hit your end point, you will have to map your line length into PI ( some integer factor)._