Problem with my ball game controller/camera

Hi all, recently ive been working on my ball game but im stack at this point.
First the ball could move [left,forward,back,right] and the script i had was SmoothFollow to follow the ball.
The SmoothFollow script didnt worked as i wanted as i wanted the camera to rotate while the player changes direction [Example : If you roll ball forward and camera is behind, you go left and in smooth follow the camera didnt rotate as the ball went left it just kept staying in same rotation, looked like 2d type of game. What i wanted is when you go forward camera is behind but when you turn left the camera rotates right so its always behind the ball and follows it .]
So i did it found script that does it

using UnityEngine;
using System.Collections;

public class Cameras : MonoBehaviour
{
    public Transform ballObject, ballCamera;
    public float speed, turnSpeed;
    Vector3 forceDirection;
    void FixedUpdate()
    {
        transform.position = ballObject.position;
        if(Input.GetAxis("Vertical") != 0)
        {
            RollBall();
        }
        //calculate ball turning
        transform.Rotate((Vector3.up * Input.GetAxis("Horizontal") * turnSpeed), Space.World);
    }
  
    void RollBall()
    {
        //set force down camera's look direction
        forceDirection = ballCamera.transform.forward;
      
        //remove y force direction for angled camera
        forceDirection = new Vector3(forceDirection.x, 0, forceDirection.z);
      
        //add force to ball
        ballObject.GetComponent<Rigidbody>().AddForce(forceDirection.normalized * speed * (Input.GetAxis("Vertical")));
    }
}

But 1st problem is that, i dont know how to set height and distance of camera because when i play the game its like right behind ball.
2nd biggest problem is that when i press left the camera rotates right so its behind the ball thats as i want but the controls get messy because now when i go left side the camera rotates but the ball behaves like it controls on world axis, north,east,south,west no matter where the camera is facing. So for example i go left and in world it means im going south lets say but when i press forward to go as camera shows it goes right on north. Sorry i dont know how else to explain this, thats best as i could.

Here is my ball movement script .

#pragma strict

var forward = 20;
var back = -20;
var left = 20;
var right = 20;

var maxVelocity : int = 100;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function FixedUpdate()
{
if(GetComponent.<Rigidbody>().velocity.sqrMagnitude > maxVelocity)//max speed
     {
            //0.5f is less smooth, 0.9999f is more smooth
             GetComponent.<Rigidbody>().velocity *= 0.99f;
     }
if (IsGrounded())
{
if (Input.GetKey("up"))
{
GetComponent.<Rigidbody>().AddForce(Vector3.forward * forward);
}
if (Input.GetKey("down"))
{
GetComponent.<Rigidbody>().AddForce(0,0,1 * back );
}
if (Input.GetKey("left"))
{
GetComponent.<Rigidbody>().AddForce(Vector3.left * left );
}
if (Input.GetKey("right"))
{
GetComponent.<Rigidbody>().AddForce(Vector3.right * right );
}
}
if (!IsGrounded())
{
if (Input.GetKey("up"))
{
GetComponent.<Rigidbody>().AddForce(Vector3.forward * forward / 2);
}
if (Input.GetKey("down"))
{
GetComponent.<Rigidbody>().AddForce(0,0,1 * back / 2 );                  
}
if (Input.GetKey("left"))
{
GetComponent.<Rigidbody>().AddForce(Vector3.left * left / 2 );
}
if (Input.GetKey("right"))
{
GetComponent.<Rigidbody>().AddForce(Vector3.right * right / 2 );
}
}

if(!Input.anyKey) // if you dont press any key then the ball slowly stops
{
   GetComponent.<Rigidbody>().velocity = GetComponent.<Rigidbody>().velocity * 0.99;
    GetComponent.<Rigidbody>().angularVelocity = GetComponent.<Rigidbody>().angularVelocity * 0.97;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

In the attached files there is simple drawing to help understand my problem better. Tell me guys if it will be really hard to make it or not cuz i cant imagine other way as interracting with the camera script inside ball script or otherway around for example like if i press right camera rotates left and the direction changes or something.

Thanks for any help !

you could use a empty game object as a camera anchor that follows the position and rotation of the player. put the camera as a child of the anchor so it follows the movement of the anchor but maintains whatever distance it originally has from the anchor.
you can use Mathf.Lerp for a smooth follow and Quaternion.Slerp for a smooth rotation.

but as i said the other problem is that if the camera follows ball and its facing left and i press forward to go that left side it goes north in the world map instead left where its facing [see the attachment picture]

try rigidBody.AddRelativeForce instead of rigidBody.AddForce to move in the direction the ball is facing instead of its world Position

I tried and it just makes the ball bugged out like doesnt roll for long roll a bit and if i keep pressing up arrow it just go in circles

you need to simplify your code. there is too much going on. unity physics can handle most the work you just need to addForce, you dont need to slow the ball down because drag will do it for you. just increase or decrease the drag in the inspector to slow the ball when there is no input.
try this for some basic movement.

public float speed = 10;
    public float turnSpeed = 5;
    void FixedUpdate()
    {
        float s = Input.GetAxis("Horizontal");
        float f = Input.GetAxis("Vertical");
        Vector3 moveForward = new Vector3 (s,0,f);
        Vector3 turn = new Vector3 (0, s, 0);
        rigidBody.AddRelativeForce (moveForward * speed * Time.deltaTime);
        rigidBody.AddTorque (turn * turnSpeed * Time.deltaTime);
    }

to increase speed you can modifiy the floats in the inspector. If you get jittery movement use interpolate in the rigidbody inspector.y may need to freeze rotation in the z axis on the rigid body in the inspector to maintain orientation.

Ok thanks for that :slight_smile: [ Im using slow down line because i have many different ball types to chose from and for example some need to slide and have 0 drag or so ever so when you accelerate and leave it will just constantly go with that speed