timoraes in blender i navigate through frames in timeline, not seconds.
blender uses frames, yes, but frames alone mean nothing. animation is run in frames-per-second. usually animations run at 24-30-60 FPS.
with modern animation techniques, not all "frames" are filled with keys, and even if so, the software still calculates the transforms as an interpolation between two keys given the current time. this is why godot uses seconds, the animation runs from 0.0 to 10.0 and we get a point in the animation, calculated from the current time. This way we can run animations that have 24FPS at 60FPS or higher, which results in smooth transitions.
So if you want something to trigger at frame 30, and the animation runs at 30 FPS, it would have to execute at exactly 1.0 seconds, which is impossible because of float rounding errors and the time since last frame can end up skipping if there's lag. So instead we execute code in between two values, so instead of pos == 1.0, we do pos > 0.9 and pos < 1.1. It could be MORE exact, but it's unlikely to be noticeable in a game.
timoraes Can you show me a example on how to use timer for this? Creating a pseudo-frame is not safe due to FPS variation
here's code from one of my projects, with some comments:
var interact_timer : float = 0.0#this changes all the time
var interact_limit : float = 0.1#this is how long the timer is
func _physics_process(delta):
if interact_timer < interact_limit:
interact_timer += delta #here delta is supposed to be the same every time because _physics_process runs 60 times per second
func Attack(DAM : int) -> void:
if weapon_collision:
if weapon_collision.has_overlapping_bodies():
for i in weapon_collision.get_overlapping_bodies():
if i.has_method("Damage"):
if interact_timer > interact_limit:#timer has finished so we run the function
i.Damage(unique_id, DAM)
interact_timer = 0.0 #we start the timer