0 votes

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

asked Mar 1, 2017 in Projects by dezekeerjoran (47 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 , >=, <=, <, >

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

const MAX_VELOCITY = 200

func _fixed_process(delta):
    if(get_linear_velocity().y > MAX_VELOCITY):
        print("Do reload here")
answered Mar 1, 2017 by avencherus (4,042 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.