Attach momentum to elevator
This commit is contained in:
25
client/Scripts/Component/LandingArea.gd
Normal file
25
client/Scripts/Component/LandingArea.gd
Normal file
@ -0,0 +1,25 @@
|
||||
extends Area2D
|
||||
|
||||
var player_node
|
||||
|
||||
func _ready():
|
||||
connect("body_entered", self, "_on_body_enter")
|
||||
connect("body_exited", self, "_on_body_exit")
|
||||
set_process(false)
|
||||
|
||||
func _on_body_enter(body):
|
||||
if body.has_method("user_input"):
|
||||
player_node = body
|
||||
set_process(true)
|
||||
|
||||
|
||||
func _on_body_exit(body):
|
||||
if body.has_method("user_input"):
|
||||
body.floor_speed = Vector2.ZERO
|
||||
set_process(false)
|
||||
|
||||
func _process(delta):
|
||||
if get_parent().motion.y > 0:
|
||||
player_node.floor_speed = get_parent().motion
|
||||
else:
|
||||
player_node.floor_speed = Vector2.ZERO
|
@ -44,6 +44,8 @@ func start_moving(index):
|
||||
func stop_moving():
|
||||
emit_signal("elevator_stopped")
|
||||
moving = false
|
||||
motion = Vector2.ZERO
|
||||
|
||||
# Alert doors of updated elevator state
|
||||
for door_path in doors:
|
||||
get_node(door_path).on_elevator_stop(current_pos)
|
||||
@ -54,6 +56,7 @@ func _physics_process(delta):
|
||||
var target_pos = intial_pos + relative_positions[current_pos]
|
||||
var angle = get_angle_to(target_pos)
|
||||
var velocity = Vector2(cos(angle),sin(angle))
|
||||
motion = velocity * elevator_speed
|
||||
global_position += velocity * elevator_speed * delta
|
||||
|
||||
# Stop when elevator is at destination
|
||||
|
@ -14,6 +14,7 @@ var jumped = false
|
||||
|
||||
var moveMotion : float = 0 # Player Input ( <- & -> )
|
||||
var motion : Vector2 = Vector2(0,0) # Player's current velocity
|
||||
var floor_speed : Vector2 = Vector2.ZERO
|
||||
|
||||
var gui # Node representing GUI object
|
||||
|
||||
@ -104,6 +105,7 @@ func _physics_process(delta):
|
||||
|
||||
# Apply velocity to frame
|
||||
motion.x = moveMotion
|
||||
motion = motion + floor_speed
|
||||
animation_manager(moveMotion)
|
||||
move_and_slide(motion, Vector2(0,-1))
|
||||
|
||||
|
Reference in New Issue
Block a user