Description

The AddForce function impacts how your GameObject moves by allowing you to define your own force vector, as well as choosing how to apply this force to the GameObject (this GameObject must have a Rigidbody component attached).

ForceMode allows you to choose from four different ways to affect the GameObject using this Force: Acceleration, Force, Impulse, and VelocityChange.

void FixedUpdate()
{
//If the current mode is not the starting mode (or the GameObject is not reset), the force can change
if (m_ModeSwitching != ModeSwitching.Start)
{
//The force changes depending what you input into the text fields
m_NewForce = new Vector3(m_ForceX, m_ForceY, 0);
}

//These are the modes ForceMode can force on a Rigidbody
//This is Acceleration mode
case ModeSwitching.Acceleration:
//The function converts the text fields into floats and updates the Rigidbody’s force
MakeCustomForce();

//This is Force Mode, using a continuous force on the Rigidbody considering its mass
case ModeSwitching.Force:
//Converts the text fields into floats and updates the force applied to the Rigidbody
MakeCustomForce();

//This is Impulse Mode, which involves using the Rigidbody’s mass to apply an instant impulse force.
case ModeSwitching.Impulse:
//The function converts the text fields into floats and updates the force applied to the Rigidbody
MakeCustomForce();

//This is VelocityChange which involves ignoring the mass of the GameObject and impacting it with a sudden speed change in a direction
case ModeSwitching.VelocityChange:
//Converts the text fields into floats and updates the force applied to the Rigidbody
MakeCustomForce();