forked from team-sg/hero-mark-2
make spider boundaries relative and clamp to the ceiling
This commit is contained in:
parent
e2452ed14c
commit
343151ebdf
1 changed files with 5 additions and 7 deletions
|
@ -12,6 +12,9 @@ export var down_boundary = 0
|
||||||
#var floor_y = 0.0
|
#var floor_y = 0.0
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
down_boundary = max(5.0, hitbox.position.y + down_boundary * 8.0)
|
||||||
|
up_boundary = max(5.0, hitbox.position.y - up_boundary * 8.0)
|
||||||
|
|
||||||
var raycast = $RayCast2D
|
var raycast = $RayCast2D
|
||||||
# detect ceiling
|
# detect ceiling
|
||||||
raycast.force_raycast_update()
|
raycast.force_raycast_update()
|
||||||
|
@ -19,17 +22,12 @@ func _ready():
|
||||||
global_position.y = raycast.get_collision_point().y
|
global_position.y = raycast.get_collision_point().y
|
||||||
hitbox.global_position.y = old_y
|
hitbox.global_position.y = old_y
|
||||||
line.points[1].y = hitbox.position.y
|
line.points[1].y = hitbox.position.y
|
||||||
# detect floor
|
|
||||||
raycast.cast_to = Vector2(0.0, 192.0)
|
|
||||||
raycast.force_raycast_update()
|
|
||||||
#floor_y = to_local(raycast.get_collision_point()).y - 3
|
|
||||||
down_boundary *= 8
|
|
||||||
raycast.queue_free()
|
raycast.queue_free()
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
hitbox.position.y += direction * speed * delta
|
hitbox.position.y += direction * speed * delta
|
||||||
if hitbox.position.y < 5.0:
|
if hitbox.position.y < up_boundary:
|
||||||
hitbox.position.y = 5.0
|
hitbox.position.y = up_boundary
|
||||||
direction = 1.0
|
direction = 1.0
|
||||||
if hitbox.position.y > down_boundary:
|
if hitbox.position.y > down_boundary:
|
||||||
hitbox.position.y = down_boundary
|
hitbox.position.y = down_boundary
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue