Hello I am making a 2D game but I need the camera to follow the player (which Is a sprite) without rotating. For example my code for the player includes a rotation for the player to face the other side when he walks that way. But whenever I attach the camera to the player the camera follows the player when he rotates, therefore you are able to see the backside of the level, I was wondering if it is possible to have the camera follow the player without it rotating to the back of the level, and have the player still able to face the direction he is walking in. Here is the script attached to the player
using UnityEngine;
using System.Collections;
public class playercontrol : MonoBehaviour {
void Update ()
{
Movment ();
}
void Movment()
{
if(Input.GetKey (KeyCode.D))
{
transform.Translate(Vector2.right *4f* Time.deltaTime);
transform.eulerAngles = new Vector2(0, 0);
}
if(Input.GetKey (KeyCode.A))
{
transform.Translate(Vector2.right *4f* Time.deltaTime);
transform.eulerAngles = new Vector2(0, 180);
}
if(Input.GetKey (KeyCode.W))
{
transform.Translate(Vector2.up *6f* Time.deltaTime);
}
}
}
Sorry if this sounds over complicated, Thanks
↧