- Home /
My camera rotates horizontally but not vertically!
So i have this script which only allows my camera to move horizontally, what do i need to add to get it to use the Y axis as well?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerFollow : MonoBehaviour {
public Transform PlayerTransform;
private Vector3 _cameraOffset;
[Range(0.01f, 1.0f)]
public float SmoothFactor = 0.5f;
public bool LookAtPlayer = false;
public bool RotateAroundPlayer = true;
public float RotationsSpeed = 5.0f;
void Start () {
_cameraOffset = transform.position - PlayerTransform.position;
}
void LateUpdate () {
if(RotateAroundPlayer)
{
Quaternion camTurnAngle =
Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationsSpeed, Vector3.up);
_cameraOffset = camTurnAngle * _cameraOffset;
}
Vector3 newPos = PlayerTransform.position + _cameraOffset;
transform.position = Vector3.Slerp(transform.position, newPos, SmoothFactor);
if (LookAtPlayer || RotateAroundPlayer)
transform.LookAt(PlayerTransform);
}
}
thnx in advance!
Answer by Zymurer · Dec 18, 2018 at 01:50 PM
I think you need to add a line under this code:
Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationsSpeed, Vector3.up)
and write this :
Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * RotationsSpeed, Vector3.left)
// Or right it depends on you.
thnx for your reply! but this was the first thing i tried already, yet nothing happens. only horizontal camera movement but nothing vertically .... any further help would be appreciated!!
Why don't you make a script to turn your camera by yourself $$anonymous$$aster Indie channel has a toturial about it (if you want to rotate your camera)
Follow this link:https://www.youtube.com/watch?v=3JsuldsGuNw
Answer by jimmycrazyskills · Dec 18, 2018 at 01:56 PM
Hi mate, I'm not sure if this will help but it might be because in your code you have this line:
Quaternion camTurnAngle = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationsSpeed, Vector3.up);
On this line you are rotating in relation to Vector3.up
, you might need another line to say Rotate on either Vector3.right
or Vector3.forward
(not sure which is appropriate in your example so try both with the code below)
camTurnAngle.AngleAxis( Input.GetAxis("Mouse Y") * RotationsSpeed, Vector3.right);
Try adding this line above the _cameraOffset = camTurnAngle * _cameraOffset;
line already in your code (P.S I've not tested this so sorry if it's wrong!)
Hope this helped mate :)
when i add the line, it doesn't load, something to do with CamTurnAngle it says. i still can't figure out why it doesn't work.
any further help would be appreciated! thnx!
Answer by maxiicanowow · Dec 18, 2018 at 02:18 PM
Basically i have a third person view, and want to change the camera with my mouse/right joystick around both horizontal and vertical axis.
if someone has a similar code, will you please let me use it?
Your answer
Follow this Question
Related Questions
Why Do I Have Camera Stutter? 1 Answer
How do I make a camera add torque on two different axis? 0 Answers
How to have free rotation camera? 1 Answer
camera movments fixed.. character controller without using character controller -.-' 2 Answers
How to rotate camera around an object to a certain amount of degrees? 2 Answers