Skip to content

Commit 4fbed67

Browse files
authored
Update ReleaseSpring.cs
1 parent 73586e2 commit 4fbed67

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Assets/Scripts/ReleaseSpring.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
public class ReleaseSpring : MonoBehaviour
44
{
5-
public Rigidbody2D ballRigidbody;
6-
public FixedJoint2D fixedJoint;
7-
public float springForce = 20f; // Increase for higher jump
8-
public KeyCode activationKey = KeyCode.Space;
5+
[Header("References")]
6+
[SerializeField] private Rigidbody2D ballRigidbody; // Ball to launch
7+
[SerializeField] private FixedJoint2D fixedJoint; // Joint connecting the ball
98

10-
void Update()
9+
[Header("Settings")]
10+
[SerializeField] private float springForce = 20f; // Adjustable spring force
11+
[SerializeField] private KeyCode activationKey = KeyCode.Space; // Key for activation
12+
13+
private void Update()
1114
{
1215
if (Input.GetKeyDown(activationKey))
1316
{
@@ -20,7 +23,13 @@ private void ReleaseBall()
2023
if (fixedJoint != null)
2124
{
2225
Destroy(fixedJoint); // Release the ball from the spring
23-
ballRigidbody.AddForce(Vector2.up * springForce, ForceMode2D.Impulse); // Apply upward force
26+
ApplySpringForce();
2427
}
2528
}
29+
30+
private void ApplySpringForce()
31+
{
32+
Vector2 launchDirection = Vector2.up; // Defined direction for clarity
33+
ballRigidbody.AddForce(launchDirection * springForce, ForceMode2D.Impulse); // Launch the ball
34+
}
2635
}

0 commit comments

Comments
 (0)