- Home /
2D Object Rotation
Hi,
I am trying to create a temperature valve which goes from open to close based on the difference between the inside temperature of an aircraft and a target temperature.
Basically the further away the cabin temperature is away from the target the valve moves further towards the open position and vise versa but after the difference is at a certain point it should be fully open. But if the temperature equalizes the valve should stop and stay in the position its in.
For example if the target temp is 23 degrees Celsius and it is 0 degrees celsius or less inside the cabin it should be fully open but if its 11.5 it should be halfway or 23 and above to be fully closed.
I have set up two targets Quaternions for open and close and can move between the two using:
public void SetRot(Vector3 _targetPos)
{
Vector3 targetDir = _targetPos - valve.transform.localPosition;
float angle = Mathf.Atan2(targerDir.y, targetDir.x) * Mathf.Rad2Deg;
Quaternion CurrentRot = valve.GetComponent<RectTranform>().localRotation;
targetRot = Quaternion.AngleAxis(angle, Vector3.forward).normalized;
manager.valve.StartInvoke();
valve.GetComponent<Valve>.elapsedTime = 0.0f;
}
This works fine for rotating between the two points and i use Quaternion.RotateTowards rather than lerp to avoid the slow down when changing directions suddenly.
I hope, I explained this as well as I could. Any help would be amazing.
Thank you.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Rotate to where the player is moving 1 Answer
Flip over an object (smooth transition) 3 Answers