0 votes

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.

Godot version v3.3.2
in Engine by (55 points)

1 Answer

+1 vote

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.

by (728 points)

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.

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())
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.