Mouse move function start after Mouseclick event

Hello guys, i need some help, if you have some time , please try to figure out with me how can i do that.

I have some Mousemove function, specifically i am throwing ball with mouse move and after some Y - position it will applyimpulse. But i want to start it after i will click on the Ball with left button of the mouse. But, as you know, Mouse move function starts immediately when i start the game. Is there some code, which should help me?

Please, help me if you know how i can possibly do that.
Thanks.

Hey, you can check whether the mouse is pressed or not and if the mouse is not pressed, you shouldn’t run the logic. Here is how you can check it.

// Paste this in Initialize function of the script to bind mouse events
if (this.app.mouse) {
        this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
        this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
        this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);
    }
myScript.prototype.onMouseDown = function(event) {
    this.isMousePressed = true;
   // console.log("mouseDown");
};
myScript.prototype.onMouseMove = function(event) {
    if (this.isMousePressed)
       // run the logic
};
myScript.prototype.onMouseUp = function(event) {
    this.isMousePressed = false;
};

You can further learn about the mouse events here : Mouse | PlayCanvas API Reference

1 Like

Thank you so much !
I will try it.

And something like that is also on tuch move?