-
Notifications
You must be signed in to change notification settings - Fork 0
/
balldragging.gd
69 lines (51 loc) · 1.5 KB
/
balldragging.gd
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
extends RigidBody2D
var mouseInside = false
var mousePressed = false
var shouldDrag = false
# Called when the node enters the scene tree for the first time.
func _ready():
print("epic") # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_body_entered(body):
#print(body)
#print(self.get_position())
#print(body.get_position())
pass
func _input(event):
if event.is_action_pressed("mouse"):
print("prssed")
mousePressed = true
if(mouseInside):
shouldDrag = true
self.set_gravity_scale(0)
elif event.is_action_released("mouse"):
print("released")
mousePressed = false
shouldDrag = false
self.set_gravity_scale(1)
func _physics_process(delta):
var mouse_position = get_viewport().get_mouse_position()
var movementDir = mouse_position - self.position
if mousePressed and shouldDrag:
print("movementdir",movementDir)
#self.set_position(mouse_position)
self.apply_force(movementDir*(mouse_position.distance_to(self.position)))
func _on_mouse_entered():
mouseInside = true
print("mouseinside")
func _on_mouse_exited():
mouseInside = false
print("mouseinside")
func _on_mouse_shape_entered(shape_idx):
mouseInside = true
print("mouseinside")
func _on_mouse_shape_exited(shape_idx):
mouseInside = false
print("mouseinside")
func _on_input_event(viewport, event, shape_idx):
print("Any input event")
if event is InputEventMouseButton:
if event.is_pressed():
print("Object clicked")