All Questions



Waypoints don't get the last point in PING_PONG mode

In the get_next_point_position method, the line:

if index < 0 or index == points.size( ) - 1:

should be replaced by:

if index < 0 or index == points.size( ):

otherwise, the platform would not move to the last point in PING_PONG mode.

  • Nathan Lovato replied

    Thanks for the pointer. I'm seeing the code is a bit different in the final course and works:

    func get_next_point_position():
    	match mode:
    			_active_point_index = (_active_point_index + 1) % get_child_count()
    			var index: = _active_point_index + _direction
    			if  index < 0 or index > get_child_count() - 1:
    				_direction *= -1
    			_active_point_index += _direction
    	return get_current_point_position()
  • L
    Mathieu01 replied

    points.size() instead of get_child_count().

  • Nathan Lovato replied

    As I wrote above, the implementation above is working. It's a copy from the final project.

    It doesn't use a points property defined in GDScript; instead, it directly uses the array of children and the Node class's API.