- Home /
Player making a 360° looping, camera not following
Hi people!
I'm in trouble again, I made a level where the player is constantly accelerating to its local forward, and we guide him like a missile through obstacles (a little like in Rayman 3 if you remember).
Problem is, I want to make more than 90° loops, and that's where the camera doesn't follow.
Actually past 90°, camera AND player rotate 180° around the forward axis of the player, so its "head up and feet down". But I want the player to keep going "feet up and head down", because its a looping.
I think it's in the Cam Script in the Update. Made several changes but can't find the fix.
Here's the Camera script :
{
public Transform lookAt;
public Transform camTransform;
private Camera cam;
public float distance = 8.0f;
public float currentX = -160.0f; //starting position
public float currentY = 10.0f; //starting position
public float sensitivityX = 4.0f;
public float sensitivityY = 1.0f;
private void Start()
{
camTransform = transform;
cam = Camera.main;
transform.forward = Camera.main.transform.forward;
}
I GUESS THE PROBLEM COMES FROM HERE - Update !
private void Update()
{
currentX += Input.GetAxis("Mouse X");
currentY -= Input.GetAxis("Mouse Y");
}
public float heighT = 6;
private void LateUpdate()
{
Vector3 height = new Vector3(0, heighT, 0);
Vector3 dir = new Vector3(0, 0, -distance);
Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
camTransform.position = lookAt.position + rotation * dir;
camTransform.LookAt(lookAt.position + height);
}
}
The controls script :
{
public float speed = 10.0f;
public Rigidbody rb;
public float Forw = 1F;
public float Cam = 50F;
public Camera mainCamera;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
transform.forward = Camera.main.transform.forward;
if (Forw <= 80) Forw += 0.01F; // to accelerate the player see further.
mainCamera.GetComponent<Camera>().fieldOfView = Cam;
if (Cam<=90) Cam += 0.01F; // modifying the field of view.
}
void FixedUpdate()
{
rb.velocity = transform.forward * Forw;
}
}
That kind of level setting
Because when I look up it's 90° value and if I turn further
currentY -= Input.GetAxis("$$anonymous$$ouse Y");
is messed up probably.
Or it's the LateUpdate...
Your answer
Follow this Question
Related Questions
TPS Rotation Camera (similar to WoW or any other mmo) 0 Answers
easing camera rotation after mouse up? 0 Answers
Rotate objects face to camera 1 Answer
Rotate within range 1 Answer
Mouse control rotate around player 0 Answers