I'm currently working on a game based on MORDHAU, a game by Triternion.
One of the main elements in MORDHAU is its melee combat. I'm currently trying to have the players crosshair turn in the same direction as the mouse's movement.
I have all the GUI elements in place, all I need to figure out is how I'd approach changing the orientation of the ImageLabel with the mouse's movement, which shows the player which direction they'll swing.
Is this possible, and if so, how should I go about it?
Edit:
I've started a basic version with a horizontal and vertical response, which seems to be working fine.
userinput.InputChanged:connect(function(inputObj) if (inputObj.UserInputType == Enum.UserInputType.MouseMovement) then local dx = inputObj.Delta.X; local dy = inputObj.Delta.Y; print("UI: (" .. tostring(dx) .. ", " .. tostring(dy) .. ")" ); if dx > 0 and dy == 0 then crosshair.Rotation = 0 elseif dx < 0 and dy == 0 then crosshair.Rotation = 180 elseif dx == 0 and dy > 0 then crosshair.Rotation = 90 elseif dx == 0 and dy < 0 then crosshair.Rotation = -90 end end end)
To do this, you would want to use the player's mouse instead. There's a function called Move
on a player's mouse.
This is how you would do it.
local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Move:Connect(function() script.Parent.Position = UDim2.new(0,mouse.X,0,mouse.Y) end)
This code will run whenever the player's mouse moves. We use the offset, because that value is put in 100's, not 1/100ths.
If you want for it to look smooth whenever you move it, or tween to a different position, you would do something like this.
local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Move:Connect(function() script.Parent:TweenPosition(UDim2.new(0,mouse.X,0,mouse.Y),"Out","Back",1,true) end)
Same thing here, but we use TweenPosition
instead.
Hope this helped! If this is what you're looking for, let me know by selecting this as an answer!