Problem with interpolation 2D movement

Godot Version

Godot 4.2.1


Hello, this is the first time I’m doing game development. I had a problem with the lerp() function. I was making zipline mechanics. When I put the lerp() line code in the zipline script for the sliding thing, the player will slide into the end point of the zipline. But the movements are instantaneous.

Here’s my code for Ziplines.

extends Node2D

@onready var playerchar: CharacterBody2D = get_node("/root/level/player")
@onready var startrope: Vector2 = $start.position
@onready var endrope: Vector2 = $end.position
@export var rope_color: Color
@export var rope_width: float
@export var rope_speed: int

func _ready():

func _draw():
	$start/point.modulate = rope_color
	$end/point.modulate = rope_color

func start_zipline():
	playerchar.position = lerp(startrope, endrope,0.5)

func _on_start_body_entered(body):
	if playerchar == body:

And this is the one-line code of usage lerp().

playerchar.position = lerp(startrope, endrope,0.5)

Are there any ideas for solving the problems?

But if I put lerp() in the player script, the player moves well. But I can’t set the position of ropes in the player script since it will be overwritten with other inheritances of Node “Ropes”.

You code moves the player to the midpoint between startrope and endrope. For continuous movement you need to change the position once per frame.
For example:

var progress = 0.0
const SPEED = 0.5

func _ready():

func start_zipline():
    playerchar.position = startrope
    progress = 0.0

func end_zipline():
    playerchar.position = endrope

func _physics_process(delta):
    progress += SPEED * delta
    if progress >= 1.0:
        playerchar.position = startrope.lerp(endrope, progress)

It may also be a good idea to disable player movement, while the zipline is active.

Depending your game design, using Tweens could be a valid solution as well.