Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Guilherme |
I have the “player” scene the script I did on it was based on the example that comes with the godot engine “Multiplayer Bomber”. My problem is that I want my game to have offiline support and also the online. When I start the game as it was offiline it from the connection error I wanted to know how I can solve the problem with my scene.
This is the code for my “player” scene.
var motion = Vector2()
func _physics_process(delta):
motion.y += GRAVITY
if (is_network_master()):
$camera.make_current()
if Input.is_action_pressed("p1_right"):
motion.x = SPEED
$Sprite.flip_h = false
$Sprite.play("walking")
elif Input.is_action_pressed("p1_left"):
motion.x = -SPEED
$Sprite.flip_h = true
$Sprite.play("walking")
else:
$Sprite.play("idle")
motion.x = 0
if is_on_floor():
if Input.is_action_just_pressed("p1_jump"):
motion.y = JUMP_HEIGHT
$Sprite.play("jump")
else:
$Sprite.play("jump")
motion = move_and_slide(motion, UP)
rset("slave_motion", motion)
rset("slave_pos", position)
else:
position=slave_pos
motion = slave_motion
var new_anim = "idle"
if (motion.y <= 0):
new_anim = "jump"
elif (motion.x < 0):
new_anim = "walking"
$Sprite.flip_h = true
elif (motion.x > 0):
$Sprite.flip_h = false
new_anim = "walking"
if (new_anim != current_anim):
current_anim = new_anim
get_node("Sprite").play(current_anim)
if (not is_network_master()):
slave_pos = position # To avoid jitter
func _ready():
slave_pos = position