Question by
Dacexi · Aug 29, 2015 at 09:28 PM ·
rotationjavascripttransformparent
How do i make a child not rotate with the parent. But i still want to be able to rotate it? (2D)
I have an arm pointing towards the cursor attached to the player. When i turn around the arm inverts it's rotation(up = down, left=right). Does anyone know how to fix this. It has to be inside the player because im spawning it with the NetworkManager.
Script JS: var mouse_pos : Vector3; var target : Transform; //Assign to the object you want to rotate var object_pos : Vector3; var angle : float; var angleY : float;
function Update () {
mouse_pos = Input.mousePosition;
mouse_pos.z = 5.23; //The distance between the camera and object
object_pos = Camera.main.WorldToScreenPoint(target.position);
mouse_pos.x = mouse_pos.x - object_pos.x;
mouse_pos.y = mouse_pos.y - object_pos.y;
angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(Vector3(0, 0, angle));
Comment