I’m trying to make a system where I can click and as long as I haven’t released my click I’m drawn towards the part (kind of like ODM gear from Attack On Titan if you’re familiar)
Well, I feel as though my REAL issue is that I’m new to working with physics constraints and I have a lackluster knowledge of CFrame/Vector math.
Here’s the problem I’m posting about… For some reason, Linear Velocity seems to almost have a “drag” when its correcting for where I’m trying to face the attachment.
It’s hard to explain and I may not be understanding my issue correctly,
so here’s a video demonstrating it:
https://i.gyazo.com/833c3b551b5f61ec2c75a571381851c8.mp4
It may be hard to notice in the video but the blue arrow, if I’m not mistaken, is where the linear velocity is moving me towards, and then the red, forcefield, part is where I’m trying to end up (where I’ve clicked)
Here’s my code:
if gpe then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local mouseHitPos = mouse.Hit.Position
if (mouseHitPos - char.HumanoidRootPart.Position).Magnitude > maxStuds then
warn("TOO FAR")
elseif debounce == true then
warn("DEBOUNCE")
else
debounce = true
lineCast = true
local clickPart = Instance.new("Part")
clickPart.Anchored = true
clickPart.Name = "clickPart"
clickPart.Material = Enum.Material.ForceField
clickPart.Color = Color3.fromRGB(255, 0, 4)
clickPart.Position = mouseHitPos
clickPart.Size = Vector3.new(1.25,1.25,1.25)
clickPart.CanCollide = false
clickPart.CanQuery = false
clickPart.Parent = workspace
local hookAtt = Instance.new("Attachment")
hookAtt.Name = "hookAtt"
hookAtt.Parent = clickPart
if lineCast then
local hrpAtt = Instance.new("Attachment")
hrpAtt.Name = "hrpAtt"
hrpAtt.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, hookAtt.WorldPosition)
hrpAtt.WorldPosition = char.HumanoidRootPart.Position
char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, hookAtt.WorldPosition)
hrpAtt.Parent = char.HumanoidRootPart
local lv = Instance.new("LinearVelocity")
lv.Visible = true
lv.Name = "lv"
lv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
lv.MaxForce = 40000
lv.Attachment1 = hrpAtt
lv.VectorVelocity = Vector3.new(100,0,0)
lv.Attachment0 = hrpAtt
lv.Parent = char.HumanoidRootPart
while lineCast do
task.wait()
hrpAtt.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, hookAtt.WorldPosition)
hrpAtt.WorldPosition = char.HumanoidRootPart.Position
char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, hookAtt.WorldPosition)
end
delay(cpDebrisTimer, function()
if lineCast == true and hookAtt and clickPart and hrpAtt and lv then
hookAtt:Destroy()
clickPart:Destroy()
hrpAtt:Destroy()
lv:Destroy()
-- print("deleting", hookAtt, clickPart, hrpAtt, lv)
end
end)
delay(debTimer, function()
debounce = false
end)
end
end
end
end)
I’ve tried a few different things and they don’t seem to be working, I also find tutorials online to not be very helpful for my situation as they usually aren’t for moving a player towards an object (ODM gear style)
Help/Feedback is appreciated, thank you!