Rick Posted October 21, 2016 Share Posted October 21, 2016 I've had this issue before and just let it slide but curious if people have ideas on how to fix it. When drawing 2D health bars (or using Sprites it seems as well) when the camera is directly behind the character it looks centered just fine, but characters off to the side of the camera the bars don't look centered. The same idea seems to apply to Sprites where they don't look perfectly aligned when off center of the camera. I'm curious on ways to fix this. Number wise things seem to work out fine but visually it doesn't look right. Code wise I take the character position (center of it's feet) and add a value to the Y value to move it up towards the head. Then I Project() that position to get the 2D position. Then I subtract 1/2 the width of the rectangle for the x value to center it and then draw. In the screenshot you can see I'm directly behind the Rick character and it looks fine, both 2D rect and sprite name, but off to the left you can see how things don't look aligned correctly. It almost seems like to get it correctly you'd have to work with the final screen and then figure out where to draw things but not sure how one would do that (sounds like a post effect but seems odd to have health bars as a post effect and not sure of the issue of getting that post effect the correct data). Does anyone have ideas on how to get this to visually look correct? Quote Link to comment Share on other sites More sharing options...
Rick Posted October 21, 2016 Author Share Posted October 21, 2016 I'll create a pivot for the character prefabs at the exact point where I want this but I would think that's the same point that's happening when I add the y value to the 3D position so if think I would get the same result when its projected to 2d right? On a side note I would have thought projecting 3D to 2d would handle this fov issue. Quote Link to comment Share on other sites More sharing options...
Rick Posted October 21, 2016 Author Share Posted October 21, 2016 I don't doubt you and with the lines I see but for my own brain I want to explore this more. Shadmars line doesn't seem to go straight threw his head. It looks like is out his back. Scaling up the y value in 3D space I would think should always make the line go through his head. If I place a pivot at his head vs starting at his feet and moving upward in 3D space to the exact same point of where the pivot would be then those 2 3D positions would be the exact same and projecting them should produce the exact same 2d point right? So would another way of looking at this be that unique y scale values per character so that it goes up right to their heads be another way to fix it? I won't be at my computer for the rest of the day but just an exercise for my brain to understand this. With your line over Shadmar reducing the y value doesn't seem like it would ever go through his head but I'm guessing it would because of the perspective. So if we were to slowly draw that line base on slowly moving upward the y value is 3D space we would see it slanting to the left the higher we go? I'd that right? Quote Link to comment Share on other sites More sharing options...
gamecreator Posted October 21, 2016 Share Posted October 21, 2016 This is more a curiosity thing but I wonder if using SetFOV would change the bars. If so, maybe using some math in coordination with GetFOV would "fix" it. Quote Link to comment Share on other sites More sharing options...
Charrua Posted October 21, 2016 Share Posted October 21, 2016 if you want the bar over the head in 2d space project the head, and then use the 2D x axis as the center of the bar, and use the 2D Y axis minus some value to rise up (in 2D space) the bar. isn't it? Quote Paren el mundo!, me quiero bajar. Link to comment Share on other sites More sharing options...
Charrua Posted October 21, 2016 Share Posted October 21, 2016 the "someValue" should be dependent of the distance from the player and the camera, probably the angle (camera x angle) and naturally the camera FOV Quote Paren el mundo!, me quiero bajar. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.