I want to control rotation in only one axis (X) via joystick. I mean, if joystick is at top, function returns Vector2(0.0,1.0) and box is also “looking” at this point, when left returns (-1.0,0.0). I wrote function like this:
function On_JoystickMove(MovingJoystick : MovingJoystick) { Debug.Log(MovingJoystick.joystickAxis); player.transform.LookAt(Vector3(MovingJoystick.joystickAxis.x,MovingJoystick.joystickAxis.y,player.transform.position.z)); }
But in some cases ex.(1.0,0.0) gameobject ‘player’ flips in Y axis by 180 degrees. I tried many solutions posted here but actually none of them worked correctly.
Thank you! Works good and actually solved my problem but when im passing values like (1.0,0.0) i have something like 'smooth spikes' or disturbances.
– thoorneFor smooth transitions you'll have to look into Lerp or Slerp functions. I would include it but I don't have much experience using those. Because you're only messing with one angle you can try something like: Mathf.Lerp(player.transform.rotation.eulerAngles.x , angle, Time.time); http://docs.unity3d.com/Documentation/ScriptReference/Mathf.Lerp.html Just saw this too: http://docs.unity3d.com/Documentation//ScriptReference/Mathf.LerpAngle.html
– LyanAppsThank you! I have been searching all over for this solution, and finally stumbled across this post.
– animalphase