Online multiplayer controls issue
Asked Answered
F

3

0

Hey ya'll!
I've recently started learning Godot and I'm going through a multiplayer tutorial. Some of the controls I had to figure out on my own such as getting weapon aim to work off of the right analog stick. The tutorial is great and the game server/client all connect and everything works for the most part. The issue I'm running into is very strange.....When I move with the keyboard the movement of the players syncs up perfectly fine, but when I use the controller it moves both players. Has anyone run into this and know what's causing it? I've looked through the input manager and nothing seems to be all that different from what was set automatically. Here is the code for the movement and aiming.

`var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@export var bullet 😛ackedScene

func _ready():
$MultiplayerSynchronizer.set_multiplayer_authority(str(name).to_int())

func _physics_process(delta):
if $MultiplayerSynchronizer.get_multiplayer_authority() == multiplayer.get_unique_id():
if not is_on_floor():
velocity.y += gravity * delta
if (Input.is_action_just_pressed("ui_accept") or Input.is_joy_button_pressed(0,JOY_BUTTON_A)) and is_on_floor():
velocity.y = JUMP_VELOCITY

	var direction = Input.get_axis("ui_left", "ui_right")
	if direction:
		velocity.x = direction * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)

	# get analog stick direction
	var input_vector = Vector2(0, 0);
	input_vector.x = Input.get_action_strength("aim_right") - Input.get_action_strength("aim_left")
	input_vector.y = Input.get_action_strength("aim_down") - Input.get_action_strength("aim_up")
	input_vector = input_vector.normalized()

	$AttackRotation.rotation = input_vector.angle()
	
	if Input.is_action_just_pressed("fire_weapon"): 
		var b = bullet.instantiate()
		b.global_position = $AttackRotation/BulletSpawn.global_position
		b.rotation_degrees = $AttackRotation.rotation_degrees
		get_tree().root.add_child(b)
		
	move_and_slide()`
Fearfully answered 22/9, 2023 at 14:17 Comment(0)
R
0

I'm having the same problem! Did you find an answer yet? Keyboad inputs work fine, and the player movement stays seperate on each peer, but if I define some additonal actions for a joypad on the input map for the existing up, down, left, right actions I have, then as soon as I try to use the controller then both players move.
I tried it by removing the controller axes from the input map and replacing it with a 2nd set of keyboard inputs to see it it was a problem of just having multiple inputs for each action, but that didn't show the problem.
My code is basically a near-perfect copy of the example code posted here - https://godotengine.org/article/multiplayer-in-godot-4-0-scene-replication/#:~:text=The%20MultiplayerSpawner%20node%20automates%20the,add%20the%20nodes%20it%20instantiates.

Reduce answered 9/11, 2023 at 15:45 Comment(0)
R
0

...in fact, I just cloned the exact repo from that article I mentioned above and imported it, and it exhibits the exact behaviour. As soon as you bind some gamepad inputs to the actions, then it starts controlling both players. There must be something about controller input that needs to be separated out differently somehow?

Reduce answered 9/11, 2023 at 15:55 Comment(0)
R
0

..and here's my answer. Receiving inputs from gamepad on an un-focused window is expected behaviour.

https://github.com/godotengine/godot/issues/16832

It's required in certain circumstances appartrently, but does mean that for multiplayer development on a single computer where we can run multiple instances of our game, that the controller inputs will be received and processed by both instances of the game.

Use this (hack?) to over-ride - https://docs.godotengine.org/en/stable/tutorials/inputs/controllers_gamepads_joysticks.html#window-focus

Reduce answered 9/11, 2023 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.