rigidbody_pick.gd 692 B

1234567891011121314151617181920212223242526272829303132
  1. extends RigidBody2D
  2. var _picked = false
  3. var _last_mouse_pos = Vector2.ZERO
  4. func _ready():
  5. input_pickable = true
  6. func _input(event):
  7. var mouse_event = event as InputEventMouseButton
  8. if mouse_event and not mouse_event.pressed:
  9. _picked = false
  10. func _input_event(_viewport, event, _shape_idx):
  11. var mouse_event = event as InputEventMouseButton
  12. if mouse_event and mouse_event.pressed:
  13. _picked = true
  14. _last_mouse_pos = get_global_mouse_position()
  15. func _physics_process(delta):
  16. if _picked:
  17. var mouse_pos = get_global_mouse_position()
  18. if freeze:
  19. global_position = mouse_pos
  20. else:
  21. linear_velocity = (mouse_pos - _last_mouse_pos) / delta
  22. _last_mouse_pos = mouse_pos