- Home /
Question by
matthewse19 · Feb 18, 2018 at 12:37 AM ·
buildmousemacmousepositionray
mousePosition not working for Mac build
This rotation and movement script I have on the player works perfectly fine in the editor and Windows builds, but for some reason on the Mac the player will rotate back and forth instead of focus in on one spot. Here's the general gist of my code: Sorry it's pretty messy, I was trying to cut out only the seemingly important parts.
void Update () {
ray = mainCam.GetComponent<Camera>().ScreenPointToRay (Input.mousePosition);
if (plane.Raycast(ray, out distance)) {
hitPoint = ray.GetPoint (distance);
}
targetAngle = Mathf.Atan2 (hitPoint.z - transform.position.z, hitPoint.x - transform.position.x);
float val = ((-Mathf.Rad2Deg * targetAngle + 90) - (transform.eulerAngles.y));
if (Mathf.Abs (val % 360) > 5) {
//Debug.Log(Mathf.Abs (val % 360));
if((Mathf.Abs ((val % 360)) > 180)){
if (360 - Mathf.Abs ((val % 360)) > 5) {
rb.angularVelocity = new Vector3 (0, ((Mathf.MoveTowardsAngle (transform.eulerAngles.y, -Mathf.Rad2Deg * targetAngle + 90, 1) % 360) - (transform.eulerAngles.y % 360)) * rotSpeed, 0);
} else {
rb.angularVelocity = Vector3.zero;
}
}else{
rb.angularVelocity = new Vector3 (0, ((Mathf.MoveTowardsAngle (transform.eulerAngles.y, -Mathf.Rad2Deg * targetAngle + 90, 1) % 360) - (transform.eulerAngles.y % 360))* rotSpeed, 0);
}
if (val % 360 > 180 || val % 360 < 0) {
//rb.angularVelocity = new Vector3 (0, -rotSpeed, 0);
} else {
//rb.angularVelocity = new Vector3 (0, rotSpeed, 0);
}
} else {
rb.angularVelocity = Vector3.zero;
}
Comment
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Rotation of Object on single axis in direction of the mouse position 0 Answers
Ray Over Mouse 1 Answer
Game is not running on mac 1 Answer
Mac build not run on other users mac 1 Answer