Icy tower - camera issues

Godot Version

Godot 4.0.1


Hi! I am now to godot and coding. I am trying to make grame similiar to icy tower to learn, and I stumbled across and Issue I have hard time solving. I want to make a camera that starts moving when player starts moving. I don’t know how to make this happen, since while loop is not working, and I don’t know why. I probably do it all wrong so I would appreciate all helpfull tips ^^ I

type or paste code here extends 

var camera_velocity = -0.5
var camera_trigger = true

func _ready():

# It should start working from begining of the game since it's already true but it doesn't :(
func _process(delta):
	while(camera_trigger == true):
		offset.y += camera_velocity
#this is how I wanted to trigger it later
func camera(delta):
	#if Input.is_action_just_pressed("ui_accept"):

Camera2D has this functionality built-in. Make it a child of you player node, and adjust the Drag configuration.

There are some good tutorials on YouTube.

1 Like

Oh! I see, thank you but I don’t think this will solve my issue :frowning: I already tried this method and this is not what I was looking for. My idea is that the camera move itself in a constant way, and the player have to keep up with it. Additionally, the camera should start moving only when the player first start moving.

Hello =)

If you use infinity while loop, your game will be stuck at the same frame.
Use instead:

func _process(delta):
     if not camera_trigger: return
     offset.y += camera_velocity

And I think is better to use…
camera.position += camera_velocity * delta
… to move your camera :wink:

1 Like

thank you! it works! but I don’t understand this part:

if not camera_trigger: return

Could you please explain to me what it is and how it works? Thank you once again!

Basically, all function can return some value.
Useful to name some verifications or other.

Simple example:

func _possible_jump(): return on_ground and not paralize

# Here function return a complexe bool
# which was ugly to put directly after the future "if"

# Later in your code...

if _possible_jump(): _jump

Also, return end the function. So if you just want stop reading the rest of the code use return with no value after.

Here, you just cancel reading of the rest of the function if camera_trigger bool is not true ^^

1 Like

ooo! I get it now, thank you! :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.