So im trying to make a script that controls two Player in local Multiplayer

Godot Version

4.2.1

Question

extends Node2D

@onready var Player1 = $Player1
@onready var Player2 = $Player2


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	Player1.velocity.x = 1
	Player1.velocity.x = -1
	
	
	Player1.move_and_slide()	
	Player2.move_and_slide()

So i have this code but it doesnt move the player. How can i call the move and slide function from parent nodes script.

Screenshot 2024-02-19 100245

Why not put the script on each character?

extends CharacterBody2D


func _process(delta):
	velocity.x = 1
	move_and_slide()	

I triend that but it gets tedious when you have to manage to scripts and copy and paste code. And making so you can also push each other, so you have to set each other player velocities from diffrent scripts

you have to manage to scripts and copy and paste code

are you saying manage two scripts?

the exact same script file go on both players, you dont need to copy paste anyting, and the movement is made from inside,from outside you simply set some variables, like a car, the engine is inside, and you got pedals from outside, and control the engine from it, you dont know what is making the engine to move the car, but you know that the accelerator moves it, a game must work in a similar way, the main code dont must move the character, each character must move itself, the main code simply must push pedals

try this on each character (the engine)

extends CharacterBody2D
var moveRight=false

func _process(delta):
  if moveRight:
    velocity.x =  1
  move_and_slide()

this on the game controller (the pedals)

extends Node2D

@onready var Player1 = $Player1
@onready var Player2 = $Player2
func _process(delta):
	Player1.moveRight = true

each “object” has his own set of variables “inside it” you dont need extra codes or anything

Thanks that could work