How to draw an elliptical circle path for animated object?

Hi guys,
I am new to unity3d world . I want to draw an elliptical circle path for my moving object
My question how can I do this is there any way to generate the elliptical circle from mathematics equations and algorithms or should I create this path by 3dsmax.
if you have any suggestion or any related tutorial please help

Do you want a visible path? Or do you just want an object to travel along an elliptical path?

I've asked a similar question: How to make computer controlled cars? I want the road to be visible(of course), but the path'd be hidden. The'll be moving in a more complicated way though, but the answer should be similar, so pls reply to my answer too.

I need it visible path

1 Answer

1

You can use trigonometry to calculate the position of the object in the elliptical path, this way:

using UnityEngine;
using System.Collections;

public class EllipticalPathCS : MonoBehaviour {
	
	public Vector3 center = new Vector3(0, 1, 0);
	public float radiusA = 5;
	public float radiusB = 10;
	public float speed = 1;
	
	private float angle;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		angle += speed * Time.deltaTime;
		
// Calculates position with parametric form, explanation:
// http://en.wikipedia.org/wiki/Ellipse#Parametric_form_in_canonical_position
		float x = radiusA * Mathf.Cos(angle);
		float y = radiusB * Mathf.Sin(angle);
		
		transform.position = center + new Vector3(x, 0, y);
	}
}

I want the path be visible not only for moving object