42 lines
1.3 KiB
GDScript
42 lines
1.3 KiB
GDScript
extends RigidBody2D
|
|
|
|
@export var max_distance = 260.0
|
|
@export var moving = true
|
|
var alt_position = Vector2(position.x + max_distance,0)
|
|
@export var move_speed = 0.01
|
|
|
|
func _ready() -> void:
|
|
add_to_group("Hidden")
|
|
modulate = Color.DARK_CYAN
|
|
#Do not move collision boxes, it is fickle.
|
|
#on_leave(%Player2D)
|
|
alt_position = Vector2(position.x + max_distance,0)
|
|
add_to_group("MovingPlatform")
|
|
|
|
func _process(delta: float) -> void:
|
|
if position.x != alt_position.x:
|
|
position.x = move_toward(position.x, alt_position.x, move_speed)
|
|
else:
|
|
moving = false
|
|
%Player2D.is_on_moving_platform = false
|
|
#%Player2D.platform_speed = 0.0
|
|
|
|
func on_enter(body) -> void:
|
|
if %Player2D.is_on_floor() and body == %Player2D:
|
|
print("Player on moving platform.")
|
|
%Player2D.platform_speed = move_speed
|
|
%Player2D.is_on_moving_platform = true
|
|
elif body == %Player2D and !%Player2D.is_on_wall_only:
|
|
print("Player but has not landed")
|
|
%Player2D.platform_speed = move_speed
|
|
%Player2D.is_on_moving_platform = true
|
|
elif body == %Player2D:
|
|
print("SOMETHING IS WRONG WITH PLAYER")
|
|
%Player2D.platform_speed = move_speed
|
|
%Player2D.is_on_moving_platform = true
|
|
|
|
func on_leave(body) -> void:
|
|
if body == %Player2D:
|
|
%Player2D.is_on_moving_platform = false
|
|
#%Player2D.platform_speed = 0.0
|