How to make blink ability in Godot 3D?

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

So I’ve been trying to make and ability like Tracer’s Blink in Overwatch. I looked at Garbaj’s tutorial about it but it was uselles (no collision) but I found a very good script in the comments.

var dir = Vector3.ZERO
var blink = 25

if Input.is_action_just_pressed("ability"):
	dir *= blink

It works fluently, it has collision detection and looks good. The only problem is that if the speed of the player or the engine changes, so does the distance that the player will “jump”. But I want the player to “jump” the same distance no matter the speed.

:bust_in_silhouette: Reply From: Lola

Assuming

  1. dir contains the linear velocity of your player (i.e. you use it like this: move_and_slide(delta * dir)) and

  2. dir != Vector3.ZERO

you can normalize it so that it still points to the same direction but with a length of 1. By doing dir = blink * dir.normalized() you get a direction vector of length blink pointing at the same initial direction.

When I change the engine speed ( Engine.time_scale = 0.15 ), it doesn’t work anymore or atleast it does but in an unnoticable scale. I want it to “jump” the same amount in Engine.time_scale = 0.15 as it does in Engine.time_scale = 1.

20xxdd20 | 2021-07-22 11:22

This is because the delta value passed in _process is modulated by the time scale.
You can either revert it to a normalized value: delta / Engine.time_scale to ensure it will have the same value regardless of time scale (but not of frame rate) or if what you want to apply is a 1-frame teleportation simply move_and_slide without using delta:

func _physics_process(delta):
    var dir = ...
    if Input.is_action_just_pressed("blink"):
        move_and_slide(blink_distance * dir.normalized())

Lola | 2021-07-22 11:49