0
votes

I have a ball and I can use WASD or arrow keys to move the ball. The ball rolls to the direction I press, rotating to left, right, forward, or backward. I want a camera to follow the ball. The camera should have Z rotated to 34 approx, facing the ball up in the air. I want to move the camera only when I move my mouse to the left or the right, when i change direction of ball. Here is what I have so far:

private void FixedUpdate()
{   
    if(referencedCamera != null)
    {
        float miscaOrizontal = Input.GetAxis("Horizontal");
        float miscaVertical = Input.GetAxis("Vertical");
        Vector3 miscare = referencedCamera.transform.TransformDirection(
            new Vector3(miscaOrizontal , 0.0f ,miscaVertical ) ); 
        rigidbody.AddForce(miscare * viteza * Time.deltaTime);

        Debug.Log("speed"+ miscare);
    }
}
1

1 Answers

1
votes

You can create a game object to follow the ball with Vector3.Lerp, your camera must be child of that game object and add this script to the game object:

transform.Rotate(0,Input.GetAxis("Mouse X"),0);