blob: d9037a806c6eb806f9c98ef158123bdcde197942 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
extends RigidBody2D
var reset_state := false
var target_vector := Vector2.ZERO
var collision_buffer: Array
func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
if reset_state:
reset_state = false
state.transform = Transform2D(0.0, target_vector)
for idx in state.get_contact_count():
var body := state.get_contact_collider_object(idx)
if body.is_in_group("bumper"):
body.animate_bump()
apply_central_impulse(
state.get_contact_local_normal(idx) *
body.get_impulse()
)
if not collision_buffer.has(body):
collision_buffer.append(body)
get_tree().current_scene.get_node("HUD").score += 50
if state.get_contact_count() == 0:
collision_buffer.clear()
func move_body(target_position: Vector2) -> void:
target_vector = target_position
reset_state = true
|