0 votes

So I've made a 2d plat form game, for it i need to make an ability which shoots at a fast rate, slows down and then hovers above the ground. I am new to coding in Godot and have only made the object shoot in one direction but it doesn't slow down or hover in one spot. How could i possibly make the ability shoot forwards slow down then hover in one spot for a few seconds?

-Sorry if this is not worded very well.

in Engine by (36 points)

1 Answer

+1 vote
Best answer

An easy way to do this is to change the Engine.time_scale temporarily using timers. You would also want to be careful to cancel out the scaling to the time used in some way, so it isn't also slowed down.

That can be done by multiplying the scale into the duration used, or dividing the scaling out of the delta if you're using processing.

A basic example looks like this. This will slow time to 30% for 1 second for pressing any button. The timer refreshes for multiple presses.

You can also get fancier results by using easing on the value used for scaling to have it ramp up or down over time.

extends Node2D


const SCALE = 0.3
const DURATION = 1.0


func _input(e):
    if(e.is_pressed()):
        time_slow(DURATION, SCALE)


var time_remaining = 0.0

func time_slow(duration, amount):

    Engine.time_scale = amount

    time_remaining = duration
    set_physics_process(true)



func _ready():
    set_physics_process(false)

func _physics_process(delta):

    if(time_remaining > 0.0):
        time_remaining -= delta / Engine.time_scale

        print(time_remaining)

        if(time_remaining <= 0.0):

            Engine.time_scale = 1.0
            set_physics_process(false)
by (5,192 points)
selected by

Thanks a lot for the help.

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.