Force applied only if I move the cursor?

When I start the game, it doesn’t recognize the cursor position. It does only after I move it at least one pixel. If I don’t move it, it’s applied a force towards position 0,0 to my numbers.


Below is for NOT auto running event with moving numbers toward cursor on game start

If you want it to auto run when game starts but NOT go toward X0 Y0 then How to do it is little below my screenshot

I am not 100% sure if you are facing same issue as i was

So let me explain and if it does not seem to be the same you can stop reading

I made camera move when cursor is on edge of screen
So if i move cursor to left edge camera would go left
It it was on top edge camera would move to the top
And so go on for left and bottom

But problem was that by default cursor is placed at x0 y0 when i start my game
So it was from the start moving toward upper left corner which was X0 Y0
BUT when i move cursor even one pixel it is teleported to wherever i had it when starting project

So in conclusion mouse cursor is set to X0 and Y0 by default by engine
And it switched to where it actually is only after you move it at least one pixel

I solved it by creating boolean variable which by default was set to false
And it was switched to true IF mouse cursor position would change
To anything else than 1 pixel to the right of left camera border and from top 1 pixel down
Basically if cursor position changed from upper left corner +1 pixel beyond to anything else
This way i made like deadzone for mouse
Which meant that if cursor position is at X0 and Y0 do nothing unless it changes to anything above that values
Higher value for X means more to the right
Higher value to Y means more down

And it looks like this

Stuff in red rectangle is what you need for it to work
And what is in green rectangle i have the logic for moving camera when cursor is close to camera borders
You would place there your last 3 events from your screenshot

To auto start it when game launches then you would create any sprite object even one pixel image as sprite object and make it transparent/empty image
You add that object to your scene and in events at beginning of scene you place it wherever you want
And now in your events you simply move numbers instead of Cursor X and Y to that object

And now you add my 1st method where you add that boolean here and in above event to that if it is switched to true now numbers goes toward CursorX and Y instead of that object

Thanks for answering, but my game is very simple. I have no camera. It’s just one scene. All I need is moving the numbers I have in a group towards mouse cursor position. When 1 is deleted (its x position is more than 600), another one starts to move.

What i have written above is not about you doing anything to camera
It is about something happening on game launch toward X0 and Y0 position unless i move mouse cursor
Which looks exactly same as problem you described

Good morning! I’ll have a look.
The code you show me , you still do need to change the position of cursor to trigger the code.
What I need is the code recognize the cursor position without moving it. If by default the mouse position is x=0 and y=0, I guess there are no possibilities to do what I want. At least I’m out of ideas.

And i told you
That you can make by default numbers go into SOME position instead
Because there is no way to move cursor other way than moving mouse
So unless you move your mouse at beginning numbers will always go to X0 and Y0

So your only option is to by default move them to for example to center of screen unless you move your mouse then you switch to move numbers to mouse cursor

I did not try it
But MAYBE now that i think about it

Solution to your issue would be to start your game by requiring player to press some button?

Imagine this

I launch your game and now i need to press START button which is on center of screen
And now game starts

You could make that button on different layer and hide it after it is pressed

This way cursor position would be registered IF someone would moved cursor after game is launched but before start button was pressed

I think it is worth a shot

Yep. I try something like that. Thanks so much.

1 Like