-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaddle.gd
39 lines (28 loc) · 1.17 KB
/
paddle.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
extends StaticBody
# Signal that tells the ball to re-aim after hitting our paddle
signal aim_ball(trajectory)
# Get a reference to the camera
# Needed to convert our mouse position on screen to in-game coordinates
onready var camera = $"../Camera"
func _ready() -> void:
pass
func _process(delta) -> void:
pass
func _input(event) -> void:
if event is InputEventMouseMotion:
# Create a plane (the thing our paddle moves on)
# Project a ray from our mouse, and get the position it intersects the plane
# and that's the new position of the paddle
var drop_plane = Plane(Vector3(1, 0, 0), 1.01) # 1.01 prevents clipping from the gray walls
var position_3D = drop_plane.intersects_ray(
camera.project_ray_origin(event.position),
camera.project_ray_normal(event.position)
)
translation = position_3D
func _on_ball_hit(collider : Spatial, sender : Spatial) -> void:
if collider != self: return
$AnimationPlayer.play("hit") # This gives the paddle that orange blip
# Re-aim the ball.
# I emit a signal for the ball script to figure out what to do
# rather than modifying the ball's velocity directly
emit_signal("aim_ball", sender.translation - translation)