Quantcast
Channel: Questions in topic: "rotating"
Viewing all articles
Browse latest Browse all 173

Rotate a gameobject by a specific angle and stop when character doesnt move anymore

$
0
0
So basically what I am trying to do is when I move my character via joystick I want to calculate the current angle the character is rotating and the new angle in which he should rotate. for example: i am currently moving at 45 degrees. now I move the joystick to 90 degrees. So basically I want to calculate the difference between the current and new angle and than rotate at that specific angle. In this case it would be 45 to left. Here is where I calculate the new degree: void Update() { // move _rigidbody.MovePosition(transform.position + (transform.forward * leftController.GetTouchPosition.y * Time.deltaTime * speedMovements) + (transform.right * leftController.GetTouchPosition.x * Time.deltaTime * speedMovements) ); if (myX != leftController.GetTouchPosition.x || myY != leftController.GetTouchPosition.y) { //checks if player changed position. myX = leftController.GetTouchPosition.x; myY = leftController.GetTouchPosition.y; double rad = Mathf.Atan2(leftController.GetTouchPosition.y, leftController.GetTouchPosition.x); // In radians double deg = rad * (180 / System.Math.PI); // values from up right to up left : +0 to +180 and from down left to down right: -180 to -0 // double difference =....; // transform.Rotate(Vector3.up,(float)difference * Time.deltaTime); } }

Viewing all articles
Browse latest Browse all 173

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>