0 votes

Hello,
I need help with this,everything is in the question....on the basis I need ON and OFF emit particles of whether the mouse cursor is moving.
cursor is moving = emitting on
cursor is not moving = emitting = off

Scene:

Node2D - script
[
Particle2D
Thanks for help

in Engine by (450 points)
edited by

2 Answers

+1 vote
Best answer
extends Particles2D

func _ready():
    set_process_input(true)

func _input(event):
    set_emitting( event.type == InputEvent.MOUSE_MOTION )

Maybe not the most efficient way, but probably the most direct way.

by (1,330 points)
selected by

Thanks, but this isn't working for me,I don't know why?
maybe detecting mouse cursor speed?
mousespeed = 0
mouse
speed = 1

_input won't do anything without input so you can't detect a no-input.

Add a variable to control the emission and set to true inside _input the same way but set it to false at the end of each process (after using it for emission).

@eons Thanks but only with a script solution I still not get it.... where put variables?...you can show on the example?....i'm still a novice in GD script.

It should be a control/flag variable on the script.

Just think (and write if possible) what you want to do:

-If moving, it must emit particles
-In any other scenario must stop emitting

It means that you need a variable to register that "moving" event but be always off when not moving.

var moving = false #the variable

func _input(event):
    if  event.type == InputEvent.MOUSE_MOTION: #is moving
         moving = true #should emit

func _process(delta):
    set_emitting(moving) #if moving emit, if not, don't
    moving = false #always false 
    #covers all the non moving situations, input will turn to true if moving

(you must turn on process and input, of course)

That is a simple way to turn on/off flags, useful in a many scenarios where no-events change behaviors.

Thanks guys for your help..that's very helpful.

.... in the input (event) function must be at the end of the code ... set _ emitting (true) for emitting particles
....We have two options 1) use animation player + script
2) only script...... this option probably is better for framerate?

This works great:

    extends Particles2D

var moving = false #the variable

func _ready():
    set_process_input(true)
    set_process(true)


func _input(event):
    if  event.type == InputEvent.MOUSE_MOTION:
        moving = true
        set_emitting(true)

func _process(delta):
    var ms = get_global_mouse_pos()
    set_global_pos(Vector2(ms))
    set_emitting(moving)
    moving = false 
0 votes

I solved....(animation way)..Godot is great,thanks to AnimationPlayer you can animate custom mouse cursor particles.

    extends Node2D

var beruska 
var b_anim


func _ready():
    set_process(true)
    set_process_input(true)
    beruska = get_node("beruska")
    b_anim = get_node("emitting")

func _process(delta):
    var ms = get_global_mouse_pos()
    beruska.set_global_pos(Vector2(ms))

func _input(event):
    if event.type == InputEvent.MOUSE_MOTION:
        b_anim.play("emitting")

enter image description here

enter image description here

by (450 points)
edited by
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.