You shouldn’t be listening for input on the FixedUpdate.
You should listen for input on Update and apply the force on the FixedUpdate. Use a boolean to control this.
void Update(){
if (Input.GetKey(KeyCode.RightArrow)){
moveRight=true
}
}
void FixedUpdate () {
if (moveRight){
moveRight=false;
rigidbody.AddForce(Vector3.right * 5);
}
}
public class CameraController : MonoBehaviour {
public GameObject player;
private Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position;
}
// Update is called once per frame
void LateUpdate () {
transform.position = player.transform.position + offset;
}
}