- Home /
Ellipse Animation by code
I really need help, I am trying to make this 3D animation by code https://www.youtube.com/watch?v=XLjnTgXXgXk I have tried whith transform, translate, vectors3, quaternion and I am really lost, this is what I have now : https://www.youtube.com/watch?v=Rat0X-fqFyQ but I dont know how to make the line follow the green ball without moving from the blue point. I will be very grateful for your help my code : greenball.transform.position = new Vector3(center.x + a Mathf.Cos(alpha), 0, center.z + b Mathf.Sin(alpha));``redline.transform.Rotate(new Vector3(0, -5, 0), Space.World);The red line is child of the blue point.
Answer by andrew-lukasik · Apr 06, 2020 at 07:53 AM
[SerializeField] Transform greenball = null;
[SerializeField] Vector3 center = Vector3.zero;
[SerializeField] float a = 3;
[SerializeField] float b = 1;
[SerializeField] float timeScale = 10;
const float tau = Mathf.PI * 2f;
void Update ()
{
float alpha = ( Time.time * timeScale ) % tau;
Vector2 localPosition2d = new Vector2{
x = Mathf.Cos(alpha) * a ,
y = Mathf.Sin(alpha) * b
};
greenball.position = center + new Vector3{ x=localPosition2d.x , z=localPosition2d.y };
}
It worked for the movement of the ball, but I was still missing the one of the line, it was solved with Line Renderer I put the ball as the destination of the line renderer and it worked correctly. :)
Answer by AstridLongi · Apr 06, 2020 at 06:07 PM
I work with Line Renderer I put the green ball as the destination of the line renderer and it worked correctly. :) https://youtu.be/is_93FB3wsA
Your answer
Follow this Question
Related Questions
Why is this rotation acting odd? 0 Answers
What causes a rotation to reset after instantiation? 1 Answer
Player character X rotation going haywire on game start 1 Answer
Instantiated Objects Point towards unknown point 0 Answers
Move child objects in the opposite direction of parent object 0 Answers