I have this script on my character
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class PlayerMovement : NetworkBehaviour {
private Rigidbody2D rb2d;
private float moveSpeed;
private Camera cam;
void Start ()
{
if (isLocalPlayer)
{
cam = this.transform.GetChild (0).GetComponent<Camera> ();
cam.enabled = true;
}
rb2d = gameObject.GetComponent<Rigidbody2D> ();
moveSpeed = 100.0f;
}
void Update ()
{
float horizontal = Input.GetAxis ("Horizontal") * moveSpeed;
float vertical = Input.GetAxis ("Vertical") * moveSpeed;
rb2d.AddForce (Vector2.right * horizontal);
rb2d.AddForce (Vector2.up * vertical);
Vector2 mousePos = cam.ScreenToWorldPoint (new Vector2 (Input.mousePosition.x, Input.mousePosition.y));
float AngleRad = Mathf.Atan2 (mousePos.y - transform.position.y, mousePos.x - transform.position.x);
float angle = (180 / Mathf.PI) * AngleRad;
rb2d.rotation = angle;
}
}
the script works okay except for the last part that deals with rotating the character, the character wont rotate to follow the mouse pointer, the strange thing is that this script has worked before (albeit on older versions of unity) but has chosen to break now,
What do I need to do to get the character following the mouse pointer?
here is the characters components in the inspector if that helps.