i have 2 character body and 1 dosent appear when i launch the game

: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

please help me

:bust_in_silhouette: Reply From: zhyrin

You didn’t supply any information about what the characters are composed of, how are the characters created, you literally gave no direction for us to give help.

It’s like saying “I expected it to rain today but it didn’t. Why?”.

sorry

the first character can move in all direction(up,down,left, right)
the second character has the movement of a platformer character
here is the script for the first charachter:
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.

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()

and the script for the second character:
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()

thelegendOFGEEK | 2023-03-11 14:58