2D Toolkit Forum

2D Toolkit => Support => Topic started by: wakestudios on April 21, 2014, 11:01:27 pm

Title: Please, help me to position 2D Ortho Sprites relative to a 3D camera view...
Post by: wakestudios on April 21, 2014, 11:01:27 pm
I'm working on a dungeon-exploring 3D game using Tk2D for GUI and HUD elements in the screen I want to achieve this result:
(http://i.imgur.com/T4kL6Ai.png?1)

But as I don't know what I need to do, this is what I get:
(http://i.imgur.com/XXgtyfa.png?1)

Is there a viewport matrix operation involved? Or ScreenToWorldPos-like command?
It looks like a similar approach to get a Minimap in a game, isn't it?
I can't figure which method is more correct. Should I detach HUDs from the TK2DCamera_GUI and place them inside every 3D Character instead?


What would you guys do?


Thanks a lot, of course...


If you cannot see the images, please go to the next urls:
ref-img1: http://imgur.com/T4kL6Ai (http://imgur.com/T4kL6Ai)
ref-img2: http://imgur.com/XXgtyfa (http://imgur.com/XXgtyfa)
Title: Re: Please, help me to position 2D Ortho Sprites relative to a 3D camera view...
Post by: unikronsoftware on April 22, 2014, 02:57:36 pm
Get the position from the character -
Vector3 screenPoint = camera3d.WorldToScreenPoint(charHeadPosition);
Get a world position in the gui camera
Vector3 worldPos = cameraGUi.ScreenToWorldPoint(screen point);

Position your gui hud element to this worldPos (maybe messing with the z a little bit) and it should appear where it should.
Title: Re: Please, help me to position 2D Ortho Sprites relative to a 3D camera view...
Post by: wakestudios on April 27, 2014, 06:36:02 pm
Seems to be scaling a little when your character get close to the Camera.   Other than that, works perfect!


Thx a lot. You saved my life :)