characterbody2d problem

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

i try to do a switching between character system for my game
so i’ve maked 2 charachterbody2d but when i launched the game
the second character doe’snt appear
the first charachter can go in any direction (up,down,right,left)
the second charachter has 2d platformer movement
here are both script
extends CharacterBody2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0

Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)

func _physics_process(delta):
# Add the gravity.

# Handle Jump.
var up_dawn = Input.get_axis("ui_up","ui_down")
if up_dawn:
	velocity.y = up_dawn * SPEED
else:
	velocity.y = move_toward(velocity.y,0,SPEED)

# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
	velocity.x = direction * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()

extends CharacterBody2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0

Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)

func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta

# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
	velocity.y = JUMP_VELOCITY

# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
	velocity.x = direction * SPEED
elif velocity.x <= 0:
	$Sprite2D.flip_h = true
elif velocity.x >= 0:
	$Sprite2D.flip_h = false
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()

Hi …
What do you mean by doesn’t appear??

If you are making 2 sperate characters
You should put both in the main scene

Can you provide a pic of the node in the editor ?

Zylo_X | 2023-03-26 00:45