-
What do you want to achieve?
I have a script that is meant to move an accessory using Handles for an RP game, similar to how it is handled in After The Flash 8. I have a part that is created in the SpecialMesh of an accessory in another script used as an Adornee for the Handle which is meant to move with the accessory as it’s offset is set.
The code I have so far is listed below as part of a LocalScript. Later, I plan on making it so that the MouseButton1Up triggers it to reflect on the server as well.
local PartToMove = nil -- Set to Nil just in case!
local movetool = script.Parent -- This is the Handle
local origin = nil -- Same for here as Local PartToMove!
movetool.MouseDrag:Connect(function(a, b)
if a.Value == 5 then
PartToMove.Offset = Vector3.new(origin.X, origin.Y, -b) -- Changing the offset of the Accessory, works as intended, same goes for a lot of following lines
elseif a.Value == 2 then
PartToMove.Offset = Vector3.new(origin.X, origin.Y, b)
elseif a.Value == 1 then
PartToMove.Offset = Vector3.new(origin.X, b, origin.Z)
elseif a.Value == 4 then
PartToMove.Offset = Vector3.new(origin.X, -b, origin.Z)
elseif a.Value == 0 then
PartToMove.Offset = Vector3.new(b, origin.Y, origin.Z)
elseif a.Value == 3 then
PartToMove.Offset = Vector3.new(-b, origin.Y, origin.Z)
end
PartToMove.Part.Position = PartToMove.Parent.Position + PartToMove.Offset -- Trying to move the part inside the SpecialMesh that the Handle has it's Adornee set to
end)
movetool.MouseButton1Up:Connect(function()
origin = PartToMove.Offset
end)
game.ReplicatedStorage.accessorySelect.Event:Connect(function(x) -- 'X' is the accessory I'm getting the SpecialMesh from
PartToMove = x.Handle:FindFirstChildOfClass("SpecialMesh")
origin = PartToMove.Offset
end)
-
What is the issue?
While looking in one specific direction has it work as intended, if I try and turn away from that direction however the location of the accessory and the part within the SpecialMesh seems to ‘desync’ and the Handle goes off in a completely different direction to the Accessory. Image demonstrates what I mean, the Handles should be moving with it.
-
What solutions have you tried so far?
As I come from an Unreal Engine background, my first thought was to try and figure out how i could “rotate the vector” of the PartToMove.Offset on line 19. I couldn’t find anything on this that worked on the dev forum nor anywhere else I’ve asked. I have consulted developer friends about this (who are, admittedly, only just slightly more experienced as I am) and gotten one to look through my code in Team Create and they have drawn blanks as well.
I’m not very good at Lua, as I’ve quite literally only started seriously considering making things in it and working on this project on the Game Dev side starting around last week, so try explain things in a manner that’s easy for me to rack my brain around as a Lua beginner but someone who isn’t fully new to programming.
Thanks!
(Sorry for poor wording by the way, I’m not the best at getting myself across.)