@cybereality said:
Check this project. You can press WASD to move the mouse. To get it to work with both a real mouse and a fake mouse, you have to make a fake mouse cursor. The code should explain everything.
extends Node2D
onready var cursor = get_node("Cursor")
var mouse_pos = Vector2()
var mouse_speed = 3.0
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
func _process(delta):
var mouse_rel = Vector2.ZERO
if Input.is_action_pressed("mouse_up"):
mouse_rel += Vector2.UP * mouse_speed
elif Input.is_action_pressed("mouse_down"):
mouse_rel += Vector2.DOWN * mouse_speed
elif Input.is_action_pressed("mouse_left"):
mouse_rel += Vector2.LEFT * mouse_speed
elif Input.is_action_pressed("mouse_right"):
mouse_rel += Vector2.RIGHT * mouse_speed
if mouse_rel != Vector2.ZERO:
Input.warp_mouse_position(mouse_pos + mouse_rel)
cursor.position = get_global_mouse_position()
func _input(event):
if event is InputEventMouseMotion:
mouse_pos = event.position
it still doesnt work... has soon has i press w,s,d,a the cursor the cursor gets teleported to the upper left screen... if iam in window mode the cursor goes all the way down to the bottom right out of the window view...
i just wanted to do a basic thing... move the player with the mouse if the button is pressed...
it works fine... but frist i must put the mouse cursor in the position of the player offset, or when i click the player, he gets slightly teleported a few pixels to were mouse is, before he starts moving
if ( Input.is_action_just_pressed('mouse_button'):
mouse = player.global_position;
elif ( Input.is_action_pressed('mouse_button'):
player.position = mouse.global_position;