Detach delay vs position check

Instead of relying on a delay that would be different depending on how far back you pull the ball, wouldn’t it be more accurate to reference the RigidBody2D of the pivot and then check the transform of the pivot vs the ball?

Something like:
[SerializeField] private Rigidbody2D pivot;
private bool isLaunching = false;

void Update()
{
if (pivot.position.x - transform.position.x < 0.1f && isLaunching)
{
springJoint.enabled = false;
springJoint = null;
}

and setting isLaunching to true in the LaunchBall method.

I’ve been working on a launcher style mechanic, and wanted something more accurate. Is there a specific reason to use a time delay over a positional argument?

Logic issues with your code aside, that’s the great thing about Unity. There are almost always multiple ways to achieve a particular result. Which usually ends up with the answer to your question, “It was what I thought of at the time” or “it’s what worked first”

For tutorials, the code is sometimes kept simple so the students can learn the topic at hand with as few distractions as possible and sometimes code is made a particular way to reinforce specific learning opportunity.

5 Likes

Privacy & Terms