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();
}
void Update()
{
transform.forward = Camera.main.transform.forward;
if (Forw <= 80) Forw += 0.01F; // to accelerate the player see further.
mainCamera.GetComponent().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
![alt text][1]
[1]: /storage/temp/82859-180.jpg
↧