I’m trying to move a knife object closer to the object it hit by 0.25 studs, but I can’t find out how. I’ve tried moving it relative to the hit object, raycasting, etc.
Here’s what I have so far:
knife.Touched:Connect(function(hit)
if hit.Parent ~= char and hit ~= knife and hit ~= handle and hit.Parent.Parent ~= char then
knife.Anchored = true
keepSpinning = false
bv:Destroy()
knife.CFrame = CFrame.lookAt(knife.Position, direction)
knife.Orientation = Vector3.new(knife.Orientation.X + 240, knife.Orientation.Y, knife.Orientation.Z)
--Changing knife position here
end
end)
Basically I want to find out which way I need to move my knife for it to be closer to the object that it hit.
knife.Touched:Connect(function(hit)
if hit.Parent ~= char and hit ~= knife and hit ~= handle and hit.Parent.Parent ~= char then
knife.Anchored = true
keepSpinning = false
bv:Destroy()
knife.CFrame = CFrame.lookAt(knife.Position, direction)
knife.Orientation = Vector3.new(knife.Orientation.X + 240, knife.Orientation.Y, knife.Orientation.Z)
knife.CFrame = hit.CFrame * CFrame.new(0,0,hit.CFrame.Z / 2)
end
end)
If It goes further and not back then try this:
knife.Touched:Connect(function(hit)
if hit.Parent ~= char and hit ~= knife and hit ~= handle and hit.Parent.Parent ~= char then
knife.Anchored = true
keepSpinning = false
bv:Destroy()
knife.CFrame = CFrame.lookAt(knife.Position, direction)
knife.Orientation = Vector3.new(knife.Orientation.X + 240, knife.Orientation.Y, knife.Orientation.Z)
knife.CFrame = hit.CFrame * CFrame.new(0,0,-hit.CFrame.Z / 2)
end
end
This is what happens without moving it: 2023-08-23 11-35-08
It already stays where the hit is, though I need to move it about 0.25 studs closer to the hit object for it to look like the knife actually impaled the object.
By the way thank you for all of the help so far.
knife.Touched:Connect(function(hit)
if hit.Parent ~= char and hit ~= knife and hit ~= handle and hit.Parent.Parent ~= char then
knife.Anchored = true
keepSpinning = false
bv:Destroy()
knife.CFrame = CFrame.lookAt(knife.Position, direction)
knife.Orientation = Vector3.new(knife.Orientation.X + 240, knife.Orientation.Y, knife.Orientation.Z)
if knife.Position.Y >= 1 then
knife.CFrame = hit.CFrame * CFrame.new(0,0.25,0.25)
elseif knife.Position.Y < 1 then
knife.CFrame = hit.CFrame * CFrame.new(0,-0.25,0.25)
end
end
end
I’ve tried something like this before. It just ends up teleporting the knife to the center of the hit object, since your setting it to the hit objects CFrame. I just tried this and it worked somewhat well:
knife.Position = endPos
--endPos is the position of the mouse when the knife was thrown
The only problem with this is that it’s somewhat inconsistent, though I could use it for now until I find any bugs with it.
I thought about that before, but I thought you was scripting in ServerScript and not in LocalScript, so uh I guess I couldn’t help at all, well fortunately you figured out how to do it