Hi,
I have now been digging into rotating objs for hours now… no breakthrough
Basically I want to rotate an obj (a disc) by 180 degrees around x, when I press on it.
I have a raytrace working and a control setting the disc to true to run my function
When the disc is true=pressed it turns blue (I did it for visual control of my code) and then it should ONLY rotate once by 180 degrees.
It turns blue but keeps rotating forever.
Can’t see what’s wrong with my for loop.
My code:
var i : int = 0;
function IconFeedbackFunction()
{
for(i = 0; i < 20; i ++)
{
transform.Rotate(new Vector3(0+i, 0, 0));
renderer.material.color = Color.blue;
//transform.Rotate(Time.deltaTime * damp, Space.World);
//var target = Vector3(0, 0, 0);
//var rotate = Quaternion.LookRotation(target - transform.position);
//transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
}
}
Any pointers?
the commented lines are some of my attempts.
Not sure what the for loop is for. You should probably use Input.GetMouseButtonDown so you know your action only happens once per click. I don’t think a boolean is what you need for this. You set it to true, but do you set it to false shortly after? I’m guessing this is why it continues to rotate.
the loop was to make the obj rotate instead of just setting the value.
I will have more functionality running when my statement is true, so right now it is needed.
Pseudo: when something is one, I want the obj to rotate a fixed amount eventhough code might be running from Update()
The for loop isn’t going to make it rotate like an animation. The for loop all happens on the same frame so any of the in-betweens will not be seen. You could try putting in a yield at the end like in the example Eric5h5 has linked to.