• Make hud objects move with mouse movement?
    11 replies, posted
Im trying to get the text and the contents of my new hud to move around when you move the mouse but I don't know where to start. Any tips? *calls the Robotboy batsignal*
[QUOTE=-Natekit-;44100396]*calls the Robotboy batsignal*[/QUOTE] You mean the robo-signal? :v: Anyway, what are you trying to do? Drag'n'drop? or what?
gui.MouseX() gui.MouseY() gui.MousePos() Oh you maybe mean, when you move your head (ingame)
[QUOTE=ExtReMLapin;44100716]gui.MouseX() gui.MouseY() gui.MousePos() Oh you maybe mean, when you move your head (ingame)[/QUOTE] Yeah, when you move your head in-game, I want the hud objects to "sway" with movement like you see in other games. I am creating a futuristic gamemode, so this is for the Hud.
[QUOTE=BobCottonSwab;46638631]Yeah, when you move your head in-game, I want the hud objects to "sway" with movement like you see in other games. I am creating a futuristic gamemode, so this is for the Hud.[/QUOTE] [url]http://wiki.garrysmod.com/page/GM/InputMouseApply[/url]
How could I implement this? For example, if I wanted to use the hud from the hudreplacement from DarkRP, the code is [CODE]local function hudPaint() local x, y = 30, ScrH() - 20 local localplayer = LocalPlayer() Health = math.min(100, (Health == localplayer:Health() and Health) or Lerp(0.1, Health, localplayer:Health())) local DrawHealth = math.Min(Health / GAMEMODE.Config.startinghealth, 1) local Border = math.Min(6, math.pow(2, math.Round(3*DrawHealth))) draw.RoundedBox(Border, x + 4, y - 30, 200 - 8, 20, Color(0,0,0,200)) draw.RoundedBox(Border, x + 5, y - 29, (200 - 9) * DrawHealth, 18, Color(140,0,0,180)) draw.DrawText(math.Max(0, math.Round(localplayer:Health())), "DarkRPHUD2", x + 4 + (200 - 8)/2, y - 32, Color(255,255,255,200), 1) -- Armor local armor = localplayer:Armor() if armor ~= 0 then draw.RoundedBox(2, x + 4, y - 15, (200 - 8) * armor / 100, 5, Color(0, 0, 255, 255)) end end hook.Add("HUDPaint", "DarkRP_Mod_HUDPaint", hudPaint)[/CODE] How could I implement the hud bobbing into this example code? Thanks for your help man.
take x and y argument from inputmouseapply and then substract/add this to our local x,y var
-snip-
Get the delta of the player's view angle, smooth it a bit with lerp and voila, you've got yourself some fine HUD sway.
probably not the best way but the easiest is to draw the hud onto a 3d2d cam in front of the player's eyes
I threw this crappy code together, see what you can do with it. [CODE]local OffsUP = 0 local OffsSIDE = 0 local LastViewAngle = Angle(0, 0, 0) hook.Add("HUDPaint", "DrawHUD", function() local ViewAngle = LocalPlayer():EyeAngles() local Delta = LastViewAngle - ViewAngle // add these two values to your HUD position. OffsUP = OffsUP + ((Delta[1] - OffsUP) / 12) OffsSIDE = OffsSIDE + ((Delta[2] - OffsSIDE) / 12) // put your hud code here LastViewAngle = LocalPlayer():EyeAngles() end)[/CODE]
[QUOTE=PortalGod;46648074]probably not the best way but the easiest is to draw the hud onto a 3d2d cam in front of the player's eyes[/QUOTE] AA looks pretty bad
Sorry, you need to Log In to post a reply to this thread.