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

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dezekeerjoran
:warning: Old Version Published before Godot 3 was released.

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

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?

avencherus | 2017-03-01 10:49

It sounds like an if statement.

if velocity == x: # or , >=, <=, <, >

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

eons | 2017-03-01 11:35

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

dezekeerjoran | 2017-03-01 14:43

:bust_in_silhouette: Reply From: avencherus

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")

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

dezekeerjoran | 2017-03-01 16:26

no, thanks for helping!

dezekeerjoran | 2017-03-01 16:33