Displaying chat GUI above Game Object [SOLVED]

Hi,

I always try and solve everything myself when possible, however this one has me in circles, Ive made a couple of games using Defold but this is the first time ive tried positioning a GUI object based on a Game objects position from within the game, anyways here is my setup and the issue.

My game is setup of multiple scenes that are spawned in using the Factory method, its bascially the same one as the tutorial for the RPG map

https://defold.com/tutorials/rpgmap/

On each scene that is spawned in there can be an NPC within the scene / collection, and when my player walks next to him it displays a Chat box I have setup within my GUI, this all works fine, however im trying to get the chat box to display right next to the NPC that I have walked next to and thats were things are going wrong.

I have tried various examples from the docs and other projects but nothing seems to work.

For reference Iā€™m also not using any camera plugins and have not even added my own camera, im using the built in one defold uses as thats always worked good for me in terms of the zoom, view etc, so if I could do it with that would be perfect before having to go down any plugin route.

The ā€œscreen to worldā€ example from the docs looked like it might work for me but that uses a camera added into the game and if possible I need to not do that as ive already built 90% of the game.

Thanks for any help

did you try this one?
http://britzl.github.io/publicexamples/gui_follows_go/index.html

2 Likes

Thereā€™s also the option of using a label component to draw the text instead of GUI.

1 Like

yeah i tried that thanks, but due to all my GUI being set in place due to the set screen sizes It didnt really work properly

Cant believe I didnt know about this, however when I try and add it into my game it doesnt quite position how I would expect, lets say I add the Label next to the NPC (well its sprite), in the editor it looks fine.

However because the GameObjects position is changed within the game the label doesnt seem to move along with it, IE it becomes totally off set to the sprite itself.

The NPCs are being spawned in via a Factory method, and there X and Y set accordingly, the label doesnt seem to stay relative to the sprite.

Hope this makes sense, shame as it would have been perfect

Here are some examples, I setup the label within the NPC GameObject and it looks fine

Then I use this code to spawn an NPC GameObject into my scene

local npc_id = factory.create("#factory2", vmath.Vector3(300,500,1), vmath.quat_rotation_z(0), nil, 1.0)

However then it looks totally offset, like so.

npc2

Got them working perfectly thanks, issues I mentioned above was due to me having the wrong ā€˜materialā€™ set, I left it at whatever was the default but needed to change it, once I did the labels are displaying perfect.

Thanks saved me a huge headache and will be using them a lot moving forward :slight_smile:

3 Likes