Mouse wiggle event?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gettokiwi

Heya

I’m trying to make a mouse event where i have to hold the cursor in a circle, and it’s trying to push the cursor out of itself, like seen in many games. I searched a lot for mouse move function but i had no luck. Any idea about this?

I’m sorry but I’m not sure if I understand which effect you want to achieve. Do you have some sample videos/gifs containing this mouse event?

As far as I know there is no set_mouse_position-function but you could hide the OS specific mouse cursor and create your own with his very own movement logic.

EDIT:
Maybe the warp_mouse()-function could help?

rolfpancake | 2018-02-16 23:26

:bust_in_silhouette: Reply From: Beamer159

The following code should do what you are asking. Attach this to your circle sprite.

extends Sprite

var pixel_remainder = Vector2(0, 0)
const RADIUS = 32 * 6

func _process(delta):
    var mouse_pos = get_viewport().get_mouse_position()
    var distance = mouse_pos.distance_to(self.position)
    if distance < RADIUS:
        pixel_remainder  += (mouse_pos - self.position).normalized()
        var push = Vector2(int(pixel_remainder.x), int(pixel_remainder.y))
        pixel_remainder -= push
        Input.warp_mouse_position(mouse_pos + push)

It looks like this:

enter image description here

This is exactly what im looking for, but after copying the code it’s just warps the mouse far away from the circle instead of pushing it. What couls be the problem?

Gettokiwi | 2018-02-17 09:05