Any way to make a smooth grabbing system?

im making a first person puzzle game where you need to pick up blocks, i have made a grab system but its just kinda bad the block jitters, doesnt have collision and it just doesnt work well heres a video of it : robloxapp-20221120-1033386

the local part :

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local mouse = plr:GetMouse()
local camera = game.Workspace.CurrentCamera
local holding = plr.Character:WaitForChild("Holding")
local RunService = game:GetService("RunService")
focusing = ""
UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.E and mouse.Target then
	
		holding = plr.Character.Holding
		holding.Value = mouse.Target.Name
			game.ReplicatedStorage.Hold:FireServer(mouse.Target.Name)
		
	end	

end)

RunService.RenderStepped:Connect(function()
	wait()
	local exists = game.Workspace.CanGrab:FindFirstChild(holding.Value)
	if exists then
	exists.Massless = true
	
		local CameraLookVector = workspace.CurrentCamera.CFrame.LookVector * 10
		
		exists.AssemblyLinearVelocity = Vector3.new(0,0,0)
		
		exists.CFrame = CFrame.new(plr.Character.Head.Position) * CFrame.new(CameraLookVector.X,CameraLookVector.Y,CameraLookVector.Z)
end
end)

the serverside :

game.ReplicatedStorage.Hold.OnServerEvent:Connect(function(plr,name)
	local exists = game.Workspace.CanGrab:FindFirstChild(name)
	print(name)
	local char = plr.Character
	if char.Holding.Value ~= "" and exists then
		char.Holding.Value = ""
		exists.Massless = false
	
	
		exists:SetNetworkOwner(game.Workspace)
		
	elseif char.Holding.Value == "" and exists then
		
		exists.Massless = true
		char.Holding.Value = exists.Name
			exists:SetNetworkOwner(plr)
		
	end
	
end)

any way to make it smoother?

1 Like

I remember you were working on this, its looking good!

  • Just a question, inside the RenderStepped that wait() is actually needed?

I would try to make less work inside the RenderStepped function that is updating the CFrame, I mean, letting the RenderStep to do less work so the update of the CFrame runs faster/smoother

now it does look smoother, thanks but it still clips thru the ground

1 Like

Yup, we talked about that before, that the part will go thru walls, a solution a little dumb could be making the walls wider, the floor deeper, so the part wont have room to go thru…

Or maybe include raycasting to offset the CFrame of the part, if the raycast finds theres not enough space in front of the camera player, then use that hit position to offset the part backwards

ill try raycasting and ill see if it works

1 Like

yea but then the part kinda goes to the wall

1 Like

also by offsetting the part backwards do you mean like exists.CFrame -= ray.Distance * 2 or smth?

1 Like

It would probably be way easier to just use BodyMovers instead of a bunch of raycasts everytime you move a part.

Here’s a tutorial on a grabber that uses BodyMovers, you can edit it a bit so that the parts don’t anchor after you finish:

1 Like

Nope, tbh Im not the best in this topic, but, when I made a build system based on grid, no grid and some physics, using raycasting, reading normals, orientation for the part, offset, etc, I found that is pretty hard to achieve and took me a couple of weeks.
I cant be sure how you should offset the part if Im not working in your system, sorry I cant help with a line of code that fix it, its more like trial and error for me

@Katrist BodyMovers are deprecated, and using Mover Constraints is something I already suggested in another OP’s topic related with this same issue

You can just switch them out for their newer instances and it will work fine. It’s much easier than learning about raycasts from the start and thinking about the math.

1 Like

Idk, that depends…
This is a project for a customer with a deadline? OP has a very important update in their game that cant wait and need any solution? Or this is for learning and improve skills and game…
Learning more useful stuff - VS - doing it in a different way

I still think that Movers Constraints (new bodyMovers) or raycasting, or even both could work together to achieve this project

1 Like

i want the script to be original since my game is worked on by only me, i want to understand what im doing, not follow a random tutorial

i still need help tho, its not exactly what i want, and it wont work with my game, the part cant even go up for some reason, and even if i set the part to massless anything wont happen

well its beneficial to understand how the tutorial did it, like @Katrist said you should probably use BodyMovers.

When you set the part’s network owner to the client then they have full control over the physics of the part (where it is in the world)

BodyMovers can help you move the part with physics as its like a smooth spring that already does physics calculations

However using raycasting and cframe setting on the client will end up in a stuttery mess

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.