I'm having trouble getting timer.start() to be called, and also experiencing weird side effects. Please help! :(

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gohccg

I think I must have a fundamental misunderstanding on how to use the timer node.
I am trying to make a zelda like camera system, where the camera is locked in place,
until the character moves out of the screen. Its working fine, but I would like to freeze the character during the camera lerp. I was going to call a timer to lock the character into place during the camera transition. And that is where my problem is.

Here is what I have so far.

extends Camera2D

var width: = 1024
var height: = 640
var x_offset = width/2
var y_offset = height/2

var new_position = Vector2()
var timer 

func _ready() -> void:
	global_position = Vector2(x_offset,y_offset)
	new_position = global_position
	timer = Timer.new()
	timer.connect("timeout", self, "_grid_transition_pause")
	timer.one_shot = true
	timer.wait_time = 1
func _grid_transition_pause() -> void:

func _process(delta: float) -> void:
	var player_position = get_node("../Player").global_position
	var x = floor(player_position.x/width) * width + x_offset
	var y = floor(player_position.y/height) * height + y_offset
	new_position = Vector2(x,y)
	if player_position.x > OS.get_window_size().x:
		print("player position greater")

	if new_position != global_position:
		global_position = lerp(global_position, new_position, 0.07)
		new_position = global_position
		print("position changed")
	if Input.is_action_just_released("test_key"):
		print("test key")

I set up some print statements to try to eliminate the code as the problem. I don’t
know if the code IS the problem (I imagine it is?) but the print statements work.

To try to test the timer to see if it was working properly, I created a test Input key to
call the start method. It worked, but with an oddity. It will work as many times
as called in the first “room”. But once the camera was changed to the
next room it can no longer be called, including if the camera returns to its original

I’m at a loss here! Thanks for taking the time to look at this and help a noob
understand the timer node better!

:bust_in_silhouette: Reply From: blank

For some reason you have to put a float time into the start() fucntion, so it would be timer.start(float(timer.wait_time)) or just timer.start(1.0)

No you don’t need to. Check out the docs for Timer.start():

Starts the timer. Sets wait_time to time_sec if time_sec > 0.
This also resets the remaining time to wait_time.

Dlean Jeans | 2019-11-25 12:28