Godot v4.2.2 Stable
For my current project I am trying to have the player move along a predetermined path while still being able to move left and right, similar to games like Sin and Punishment.
I’m having a problem where I have the player moving relative to the camera when it’s a child of the level, but it stops moving relative to the camera once it becomes a child of PathFollow3D.
Using this GDQuest tutorial and the basic CharacterBody3D node, I am able to have a character that can move while on a PathFollow3D trail, however making the player a child of PathFollow3D like the tutorial suggests somehow makes it so movement isn’t relative to the camera.
This is the PathFollow3D code
extends PathFollow3D
func _physics_process(delta: float) → void:
const move_speed := 4.0
$“.”.progress += move_speed * delta
And this is the CharacterBody3D code
extends CharacterBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 4.5Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)#func _ready():
#Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)func _physics_process(delta):
Add the gravity.
if not is_on_floor():
velocity.y -= gravity * deltaHandle jump.
if Input.is_action_just_pressed(“ui_accept”) and is_on_floor():
velocity.y = JUMP_VELOCITY#if Input.is_action_just_pressed(“ui_cancel”):
#Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)var input_dir = Input.get_vector(“move_left”, “move_right”, “move_forward”, “move_back”)
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)move_and_slide()
I’m still pretty new to Godot so I’m not too sure how to go about fixing this, or why this problem is occurring in the first place.
This is also my first time making a help post like this so hopefully everything is formatted correctly.