Making my HUD work...

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

hi, i’m currently working on my project, it’s being hard to do alone but i’m going well, today my task was to make the HUD of my game work, after trying and trying i could find a way but it wasn’t the way i needed, this is how it is:

This is the script that let the player choose a color to its car and drive in that color:

    extends Control
    onready var car = load("res://Scenes/DeftoriaCar.tscn").instance()
    func _process(delta):
    	if $CenterContainer/VBoxContainer/ColorPickerButton.color:
    		$CenterContainer/VBoxContainer/ColorPickerButton/ColorEx.modulate = $CenterContainer/VBoxContainer/ColorPickerButton.color
    		car.get_node("CarColor").modulate = $CenterContainer/VBoxContainer/ColorPickerButton.color
    func _on_StartButton_pressed():
    	car = load("res://Scenes/DeftoriaCar.tscn").instance()
    	car.get_node("CarColor").modulate = $CenterContainer/VBoxContainer/ColorPickerButton.color

This is the script for my HUD:

extends Node

onready var viewport1 = $Viewports/ViewportContainer1/Viewport1
onready var camera1 = $Viewports/ViewportContainer1/Viewport1/Camera2D
onready var minimapcam = $Minimap/Viewport/Camera2D
onready var world = $Viewports/ViewportContainer1/Viewport1/WorldMain

func _ready():
	$Minimap/Viewport.world_2d = viewport1.world_2d = world.get_node("Player_1") = world.get_node("Player_1")

When testing it i came to the conclusion that i need to make the HUD know when the player has entered with the car in the game, because if i was to make in another way i would need to a lot of code to all the vehicles, but i don’t know a lot about the ways of doing it, i just want to make a little racing game, any help would be apreciated.

You would like to have your HUD follow your player?

Allan | 2018-12-18 21:29

My Hud is already following the player, but only if i phisically instance it on my world, but if i do that my cars aren’t color anymore, what i need is that the hud sees when the player enters the world.

StrikerSVX | 2018-12-18 21:36