0 votes

how to make an event happen when a certain velocity is hit?

in Engine by (53 points)

You'll have to be more specific. What velocity are you interested in? One of your own or the one reported by get_linear_velocity()? Also what axis are you interested in? X or Y? Or did you want to measure magnitude? Then what do you consider an "event"? A custom signal?

It sounds like an if statement.

if velocity == x: # or , >=, <=, <, >
  do_something()

But maybe you want something else.
Give us more details, as avencherus said.

when the player( rigidBody ) if falling so -y axis and hits 0,-200: the scene will reload. oke?

1 Answer

0 votes

A basic example for that would be:

extends RigidBody2D

func _ready():
    set_fixed_process(true)

const MAX_VELOCITY = 200

func _fixed_process(delta):
    if(get_linear_velocity().y > MAX_VELOCITY):
        print("Do reload here")
        set_fixed_process(false)
by (5,192 points)

sorry, but there is an error it says: Invalid operands 'float and 'nil' in operator '>'.

no, thanks for helping!

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.