diff options
author | cflip <cflip@cflip.net> | 2022-09-23 17:45:16 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-09-23 17:45:16 -0600 |
commit | 11b451bcea45f7ac3dc641eaf1d1ef7db6af5efc (patch) | |
tree | 7610ea8bc31f5fdb64602f7b1c1a5a7a8288f5f9 | |
parent | ed3b37f6fa7b37429f79a7d229e1134ae316ed7e (diff) |
Allow resetting of the ball
-rw-r--r-- | Basketball.gd | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/Basketball.gd b/Basketball.gd index 31642ae..d4abf21 100644 --- a/Basketball.gd +++ b/Basketball.gd @@ -1,20 +1,25 @@ extends RigidBody2D -var angular_speed = PI var start_position +var do_reset = false + # Called when the node enters the scene tree for the first time. func _ready(): start_position = position - apply_central_impulse(Vector2(500, -800)) - pass # Replace with function body. + do_reset = true + +# Override the default physics when we want to manually reset the position and rotation. +func _integrate_forces(state): + if do_reset: + state.transform.origin = start_position + state.linear_velocity = Vector2() + + apply_central_impulse(Vector2(500, -800)) + apply_torque_impulse(10000.0) -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): - rotation += angular_speed * delta + do_reset = false func _input(event): if event.is_action_pressed("shoot"): - position = start_position - rotation = 0 - apply_central_impulse(Vector2(500, -800)) + do_reset = true |