Map mouse cursor movement with right analog stick on gamepad?

Hello I’m a beginner in Godot 4.2.1. I understand how to use the Input Map to allow for player movement using the left analog stick on a gamepad.

However, I am struggling to find a simple way to map the mouse cursor movement to the right analog stick of the gamepad.

Ideally I want the user to be able to move the player with the left analog stick while also being able to place objects on screen using cursor moved by the right analog stick.

Any help/advise would be much appreciated as I have spent days looking for a simple solution to this issue with no results.

you might be able to “manually map” the analog input by moving the cursor using the warp_mouse() function

Thank you!!!

I knew it had to be something simple that I was missing. The gdscript below allows me to simultaneously move the player with the left analog stick and the cursor with the right analog stick!

extends CharacterBody2D

const speed = 300
const jump_velocity = -400

#Get gravity from the project settings to be synced with RigidBody nodes.
var gravity: int = ProjectSettings.get_setting(“physics/2d/default_gravity”)

#Move cursor using either mouse or right analog stick on gamepad
func _physics_process(delta: float) → void:
#Get input direction and handle movement
var mouse_sens = 300
var direction: Vector2
direction.x = Input.get_action_strength(“cursor_right”) - Input.get_action_strength(“cursor_left”)
direction.y = Input.get_action_strength(“cursor_down”) - Input.get_action_strength(“cursor_up”)

if abs(direction.x) == 1 and abs(direction.y) == 1:
	direction = direction.normalized()
	
var movement = mouse_sens * direction * delta
if(movement):
	get_viewport().warp_mouse(get_global_mouse_position()+movement)
	
#Move player using either keyboard or left analog stick
#Add gravity
if not is_on_floor():
	velocity.y += gravity * delta
#Handle jump
if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = jump_velocity
#Get input direction and handle movement
var player_direction := Input.get_axis("move_left", "move_right")
if player_direction:
	velocity.x = player_direction * speed
else:
	velocity.x = move_toward(velocity.x, 0, speed)
move_and_slide()
1 Like