- Home /
simulate a circle move
I wanted to make sure that my item would make a 180 ° turn. I tried something like this but did not come back. You know you help me?
#pragma strict
var incr : float = 0.1;
var angle : float = 0.0;
function Start () {
}
function FixedUpdate () {
while(angle < 180 * 6.28 / 360 ){
transform.position = Vector3(30*Mathf.Sin(angle)*Time.deltaTime, 30*Mathf.Cos(angle)*Time.deltaTime,0);
angle+=0.1;
}
}
Answer by robertbu · Aug 16, 2014 at 02:16 PM
You have two problems here. First, Mathf.Sin() takes radians, not degrees. Second is your use of while(). You want do a bit of work each frame, not do multiple moves per frame. Try this:
#pragma strict
var incr : float = 0.1;
var angle : float = 0.0;
function FixedUpdate () {
if (angle < 6.28){
transform.position = Vector3(30*Mathf.Sin(angle)*Time.deltaTime, 30*Mathf.Cos(angle)*Time.deltaTime,0);
angle+=0.1;
}
}
Answer by Peeta · Aug 16, 2014 at 03:33 PM
In the end the problem was nell'if. I had used the wile. With this code, I got what I wanted. Thanks for your help! :)
#pragma strict
var incr : float = 0.1;
var angle : float = 0.0;
function FixedUpdate () {
if (angle < 180 * 6.28 / 360){
transform.position = Vector3(100*Mathf.Sin(angle)*Time.deltaTime, 100*Mathf.Cos(angle)*Time.deltaTime,0);
angle+=0.1;
}
}
I tried to put $$anonymous$$ath.PI but did not work so I put the calculation. It was probably a small bug in the compiler to restart work again
Your answer
Follow this Question
Related Questions
Trigonometric functions 2 Answers
Creating Objects In Circle Starting at the top. 0 Answers
Move In Circle relative to rotation. 1 Answer
Trigonometry help? 1 Answer