Hello guys I was trying to make joy stick system and it’s work pretty good but there’s some issue with it because I was trying to make my joystick can move around in circle with distance between old mouse location and current mouse location(also I set every guis position and size into scale because when I use offset it’s not work for difference device.) if distance is not greater than radius or skill_2_joy_stick_border then skill_2_joy_stick will set position to
player mouse direction * distance between old mouse location and current mouse location + position of default joystick
to make it work well it’s pretty hard to explain here some video:
as you can see in the video when my mouse move in x axis it’s work very well but when it’s move in y axis it’s get shorter range
Here some of my code(This is just some of my code it’s not all I only copy the code that I think it’s cause the issue also sorry for messy code and bad variables name because I’m having pretty bad english):
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local plr = Players.LocalPlayer
local mouse = plr:GetMouse()
local old_mouse_pos_offset = Vector2.new(mouse.X, mouse.Y)
local skill_gui = script.Parent
local skill_joy_sticks = skill_gui.skill_joy_sticks
local skill_2_joy_stick_border = skill_joy_sticks.skill_2_joy_stick_border
local skill_2_joy_stick = skill_joy_sticks.skill_2_joy_stick
local z_press = false
local x_press = false
local c_press = false
local x_press_first_time = false
local radius = skill_2_joy_stick_border.Size.X.Scale / 2
function x_press_function()
x_press = true
x_press_first_time = true
end
function x_unpress_function()
x_press = false
end
UIS.InputBegan:Connect(function(input, chatting)
if chatting then return end
if input.KeyCode == Enum.KeyCode.X and not z_press and not x_press and not c_press then
x_press_function()
end
end)
UIS.InputEnded:Connect(function(input, chatting)
if chatting then return end
if input.KeyCode == Enum.KeyCode.X and x_press then
x_unpress_function()
end
end)
mouse.Move:Connect(function()
if x_press and x_press_first_time then
x_press_first_time = false
old_mouse_pos_offset = Vector2.new(mouse.X, mouse.Y)
end
if x_press then
local current_mouse_pos_offset = Vector2.new(mouse.X, mouse.Y)
local viewsizes = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY)
local current_mouse_pos_scale = current_mouse_pos_offset / viewsizes
local old_mouse_pos_scale = old_mouse_pos_offset / viewsizes
if (old_mouse_pos_scale - current_mouse_pos_scale).Magnitude <= radius then
local direction = (old_mouse_pos_scale - current_mouse_pos_scale).Unit
local distance = (old_mouse_pos_scale - current_mouse_pos_scale).Magnitude
local displacement = (-direction * distance) + Vector2.new(skill_2_joy_stick_border.Position.X.Scale, skill_2_joy_stick_border.Position.Y.Scale)
skill_2_joy_stick.Position = UDim2.new(displacement.X, 0, displacement.Y, 0)
else
local direction = (old_mouse_pos_scale - current_mouse_pos_scale).Unit
skill_2_joy_stick.Position = UDim2.new((-direction.X * radius) + skill_2_joy_stick_border.Position.X.Scale, 0, (-direction.Y * radius) + skill_2_joy_stick_border.Position.Y.Scale, 0)
end
end
end)
If anyone know how to fix this or need more infomation you can tell me in the comment.
Thank you for your help!