#I can't make my player follow my bezier path

5 messages · Page 1 of 1 (latest)

ocean carbon
#
extends CharacterBody2D

const SPEED = 300.0
const JUMP_VELOCITY = -300.0
var timer: float = 0

# Curve movement variables
var t = 0.0               # interpolation factor along the curve (0 to 1)
var curve_speed = 1.0      # speed along the curve
var following_curve = false

func _ready() -> void:
    GlobalVariables._player_hit_pipe.connect(_player_hit_pipe)

func _physics_process(delta: float) -> void:
    if GlobalVariables.lost:
        position = $Path2D/PathFollow2D.position
    else:
        # Normal gameplay
        velocity.y += 500 * delta
        timer -= delta
        if timer <= 0 and Input.is_action_pressed("ui_accept"):
            velocity.y = JUMP_VELOCITY
            timer = 0.5
        move_and_slide()

func _player_hit_pipe():
    GlobalVariables.lost = true
    timer = 0.1

So i'm trying to set up a bezier curve for my flappy bird player when he get hit by a pipe but this happens (see gif).

I have also have my nodes hierarchy in my images...

This is my PathFollow2D's script.

extends PathFollow2D


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
    GlobalVariables._player_hit_pipe.connect(_player_hit_pipe)

func _player_hit_pipe():
    set_progress_ratio(0.1)

If my question isn't clear enough, please feel free to say so and I'll rehearse my question. I'm already afraid enough that what I'm asking help for isn't comprehensible I think

#

My Path2D's script:

extends Path2D

func _ready() -> void:
    GlobalVariables._player_hit_pipe.connect(_player_hit_pipe)
    
func _player_hit_pipe():
    curve.add_point($".".position)
    curve.add_point($Marker2D.position)
    curve.add_point($Marker2D2.position)
    curve.add_point($Marker2D3.position)
    curve.add_point($Marker2D4.position)
covert rose
#

instead of doing this:

if GlobalVariables.lost:
        position = $Path2D/PathFollow2D.position

Try doing this:

if GlobalVariables.lost:
        global_position = $Path2D/PathFollow2D.global_position
#

Although, you might run into some other issues when a node tries to "follow" a node that is a child of it

#

since when the following node moves, the child moves as well