Platform lift gets stuck

extends RigidBody3D

#@onready var elevator_zone : Area3D = $Area3D
@onready var nav_link_1 : NavigationLink3D = $Level1
@onready var nav_link_2 : NavigationLink3D = $Level2

var area_nodes = [] 

var speed = 1.5
var direction = Vector3.UP
var min_y = 0
var mid_y = 8.876
var max_y = 15.634
var is_paused = false
var has_passenger = false

var nav_link_1_start_position = Vector3()
var nav_link_2_start_position = Vector3()

func _ready():
  for child in get_children():
	  if child is Area3D:
		  area_nodes.append(child)
  nav_link_1_start_position = nav_link_1.global_transform.origin
  nav_link_2_start_position = nav_link_2.global_transform.origin
 #elevator_zone.body_entered.connect(_on_body_entered)
 #elevator_zone.body_exited.connect(_on_body_exited)

func _on_body_entered(body):
  if body is CharacterBody3D:
	has_passenger = true

func _on_body_exited(body):
if body is CharacterBody3D:
	has_passenger = false

func _physics_process(delta):
nav_link_1.set_global_start_position(nav_link_1_start_position)
nav_link_2.set_global_start_position(nav_link_2_start_position)
var end_position = self.global_transform.origin
end_position.y += direction.y * speed * delta
nav_link_1.set_global_end_position(end_position)
nav_link_2.set_global_end_position(end_position)

if is_paused:
	return
#var new_position = self.global_transform.origin + direction * speed * delta
if (position.y < min_y and direction.y < 0) or (position.y > max_y and direction.y > 0):
	direction = -direction
	is_paused = true
	apply_central_impulse(-linear_velocity * mass)
	get_tree().create_timer(3.0).timeout.connect(_on_timeout)
elif (position.y >= mid_y and direction.y > 0 and position.y <= max_y):
	is_paused = true
	apply_central_impulse(-linear_velocity * mass)
	get_tree().create_timer(3.0).timeout.connect(_on_timeout)
else:
	apply_central_impulse(direction * speed * delta * mass)
	


func _on_timeout():
    is_paused = false

This code is tied to a RigidBody3D platform that moves the character from up to down, stopping at a few specific heights so that the character can get off on a static platform.
var min_y = the actual starting position
var mid_y = second platform
var max_y = third platform
After reaching mid_y, the elevating platform stops and does not move up or down. And I honestly do not know how to solve it?

I noticed your ELIF on the elevator code listens for if mid_y is GREATER OR EQUAL, so it’s likely that it’s staying paused because it doesn’t want to go past mid_y. You may consider using individual points or direct comparisions in your logic.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.