0 votes

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
    camera1.target = world.get_node("Player_1")
    minimapcam.target = 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.

in Engine by (99 points)

You would like to have your HUD follow your player?

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.