- Home /
use sin and cos with clamp values
how can I move an object with sin and cos using a range? I have to make my object rotate back and forth like a pendulum in a certain range. I thought of using the Mathf.Sin functions
if (GameManager.instance.currentDirection.dir == Vector2.right)
{
min = 0f;
max = 90f;
}
else if (GameManager.instance.currentDirection.dir == Vector2.left)
{
max = 0f;
min = -90f;
}
angle = (Mathf.Atan2(fish.gameObject.transform.rotation.y, fish.gameObject.transform.rotation.x) * Mathf.Rad2Deg);
angle = Mathf.Clamp(angle, min, max);
Quaternion rot = Quaternion.Euler(new Vector3(0,180,Mathf.Sin(Time.time)*angle));
Comment
Your answer
Follow this Question
Related Questions
clamp limit variables trouble 1 Answer
bullet rotation as its affected by gravity 2 Answers
arc object's position using sin 1 Answer
Clamping between everything but the min/max values 1 Answer
how to normalize a value to a range between 0 and 1 4 Answers