0 votes

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
    add_child(timer)

func _grid_transition_pause() -> void:
    print("success")

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")
        timer.start()

    if new_position != global_position:
        global_position = lerp(global_position, new_position, 0.07)
        new_position = global_position
        print("position changed")
        timer.start()

    if Input.is_action_just_released("test_key"):
        print("test key")
        timer.start()

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
position..

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

in Engine by (12 points)

1 Answer

0 votes

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)

by (128 points)

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.