Godot Version
Godot 4
Question
Character moves faster than camera . The problem only occurs when i have set parallax background. I debugged and confirmed the global pos of player and camera are same. But the player goes out of the viewport .
Godot 4
Character moves faster than camera . The problem only occurs when i have set parallax background. I debugged and confirmed the global pos of player and camera are same. But the player goes out of the viewport .
First, you could just make your camera a child of the player. It would go up and down when the player jumps, but if your level is more than one screen high, this will be good.
Second, you don’t need pass as part of a function ever. It’s only there to prevent compiler errors when nothing is in a function. It’s a placeholder.
Third, your problem is your camera is playing catch up. You are running it in the _process()
function instead of the _physics__process()
function, which means it is not guaranteed to run every frame. Then, you are having it find the player every frame, which slows things down.
There are a number of ways to fix this, but the best one is to have the player update the camera every time it moves:
#player.gd
@onready var camera: Camera2D = $Camera2D
func _physics_process (delta) -> void:
#do stuff here
move_and_slide()
camera.global_position.x = global_position.x
Thankyou for the response.
But the problem was solved by itself after upgrading my Godot from 4.3 to 4.4. So, I came to a conclusion that it was a bug.
I tried everything including controlling player’s velocity in physics_process, controlling camera position to match player’s position through code, new project from scratch, following yt tutorial and doing exact same thing using same assects, etc in the duration of 3 days. And without changing the code or project hierarchy I installed latest ver of godot and converted it into new version and it was solved.
I write " pass " at the end for satisfactory reasons. It makes me feel like it is end of the function hehe.
Thankyou again !