File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change 22
33public 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}
You can’t perform that action at this time.
0 commit comments