Question by
airjairj · Jun 02, 2018 at 10:06 PM ·
cameracamera followtop down shootercamera rotationtop down
Need help with camera in top down shooter
Hi, I have a problem with my camera in my top down shooter, i have a script, and it works, but it only does it when the player is NOT the parent of the camera. The problem is that now that i'm workin on a multiplayer system, the camera spawn as a child of the player, and it keeps rotating, so can someone pls convert this script in a better one(or maybe give me a new 100% working script)?? Sorry for the bad English(if it is), and here is the script: public class Camera1 : MonoBehaviour {
public GameObject camera;
private void Update()
{
Plane playerPlane = new Plane(Vector3.up, transform.position);
Ray ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);
float hitDist = 0.0f;
if(playerPlane.Raycast(ray, out hitDist))
{
Vector3 targetPoint = ray.GetPoint(hitDist);
Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
targetRotation.x = 0;
targetRotation.z = 0;
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 7f * Time.deltaTime);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612163944im_/https://answers.unity.com/themes/thub/images/avi.jpg)