Breakout Game Tutorial Question - Putting addForce in FixedUpdate makes the ball fly out of the screen at high speed?

Hey guys!

After completing this tutorial : Mini-Projects from the Recorded Video Training Archive - Unity Learn , I’ve tried to re-implement the physics of the ball in FixedUpdate(), and the ball seems to behave quite differently than the implementation in the tutorial.

I’m really interested to find out why… Here’s my code for the ball GameObject, for example :

using UnityEngine;
using System.Collections;

public class Ball : MonoBehaviour {
	
	public float ballInitialVelocity = 600f;
	private Rigidbody rb;
	private Vector3 paddlePos;

	private float ballVelocity;
	private float chargeRate = 90f;
	private bool charging = false;
    private bool launchBall = false;
    private Vector3 mousePosition;
	
	void Awake () {
		
		rb = GetComponent<Rigidbody>();
	}
	
	void Update () 
	{

		if (Input.GetButtonDown("Fire1") && GM.instance.ballInPlay == false)
		{
			ballVelocity = ballInitialVelocity;
			//Mathf.Clamp(ballVelocity, 0, 1000f)
			charging = true;
		}
		if (charging == true)
		{
			print("Before : " + ballVelocity);
			ballVelocity = Mathf.Clamp(ballVelocity + (chargeRate * Time.deltaTime), 0, 800f);
			print("After : " + ballVelocity);
		}
		if (Input.GetButtonUp("Fire1") && charging == true){
            launchBall = true;

        }
	}

    void FixedUpdate()
    {
        // Launch the ball
        if (launchBall == true)
        {
            charging = false;
            transform.parent = null;
            GM.instance.ballInPlay = true;
            rb.isKinematic = false;
            rb.AddForce(new Vector3(ballVelocity, ballVelocity, 0));
            ballVelocity = ballInitialVelocity;
        }
    }
}

I can’t really figure out why it’s behaving so differently than when it’s implemented within Update()… any ideas?

Sorry if that seems obvious ; I’ve tried looking for an answer and I couldn’t find anything in recent questions.

That’s probably because you use a velocity vector calculated with Time.DeltaTime from Update. FixedUpdate uses that automatically (see the example in the Unity Script Reference for AddForce).