2D Arm Rotation. Problems

Updated on September 23, 2017 in [A] 2D
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on September 23, 2017

I was following along with the ‘How to make a 2D platformer’ tutorial ep 5, and when I finished the arm rotation script my entire arm sprite rotated, and I didn’t want this.

 

using UnityEngine;
using System.Collections;
public class ArmRotation : MonoBehaviour {
public int rotationOffset = 90;
// Update is called once per frame
 void Update () {
 // subtracting the position of the player from the mouse position
 Vector3 difference = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
 difference.Normalize (); // normalizing the vector. Meaning that all the sum of the vector will be equal to 1
float rotZ = Mathf.Atan2 (difference.y, difference.x) * Mathf.Rad2Deg; // find the angle in degrees
 transform.rotation = Quaternion.Euler (0f, 0f, rotZ + rotationOffset);
 }
}
  • Liked by
Reply