(First post and new to everything, forgive me)
I'm setting the framework for a game where a driver can switch vehicles Code is bare bones at the moment just to test how some things work.
Right now a key press should queuefree() the player, shift camera focus to the vehicle and movement controls become enabled for the vehicle. The camera focus will change but isplayer never seems to change to true. If I just declare is_player as true everything works, even up to when I exit the vehicle and spawn the driver back in and lose control of the vehicle again.
extends KinematicBody2D
const PLAYER = preload("res://Player.tscn")
const SPEED = 100
const GRAVITY = 10
const FLOOR = Vector2(0, -1)
var velocity = Vector2()
var is_player = false
var is_dead = false
func _physics_process(delta):
velocity.y += GRAVITY
velocity = move_and_slide(velocity, FLOOR)
if is_dead == false:
if Input.is_action_pressed("enter_vehicle"):
$Camera2D.make_current()
var is_player = true
if is_player == true:
if Input.is_action_pressed("move_right"):
velocity.x = SPEED
$Sprite.flip_h = false
elif Input.is_action_pressed("move_left"):
velocity.x = -SPEED
$Sprite.flip_h = true
else:
velocity.x = 0
if Input.is_action_pressed("exit_vehicle"):
var player = PLAYER.instance()
get_parent().add_child(player)
player.position = $Exit.global_position
is_player = false