Sorry for the title, doesn’t explain the situation well.
I wanted to make a user-controllable part controlled by a mouse. The catch is that the part would have to stay in another (area) part for the whole time. Plus of course it can only slide on the ground and on the edges of the area part. I have already tried a few methods but hasn’t come up with a satisfying solution yet. The part ‘wiggles’ and continues to glitch sometimes.
Here’s the video material:
Notes:
- the area part can be seen at then end, when I close out of the test session
- the yellow part is a part which provides some light (anchored, can’t collide).
I currently use network ownership to achieve everything shown in the video, however I plan to switch to remote events (more control over the part, the part needs to be anchored and with network ownership - it can not).
Here is a part of the code which calculates where to teleport the part (Local Script):
local workspaceW = game:GetService("Workspace")
local baseplate = workspaceW:WaitForChild("Baseplate")
local function rayResult(x, y)
local unitRay = camera:ViewportPointToRay(x, y)
local origin = unitRay.Origin
local direction = unitRay.Direction
return workspaceW:Raycast(origin, direction * 250, params), origin, direction
end
local mouseLocation = game:GetService("UserInputService"):GetMouseLocation()
local result, origin, direction = rayResult(mouseLocation.X, mouseLocation.Y)
local placeToTpTo = CFrame.new(result.Position)
local baseplateCenter = baseplate.CFrame.LookVector * (baseplate.Size.Z / 2)
local partHeight = part.Size.Y
local placeToTpTo = CFrame.new(placeToTpTo.Position.X, baseplateCenter.Y + (partHeight/2), placeToTpTo.Position.Z)
part:PivotTo(placeToTpTo)
Notes:
- the script makes a few checks before teleporting, for example if the part is in the area box (it doesn’t work as expected tho because the part can sometimes glitch out)
- in the actual script
placeToTpTo
value is determined on whenever the part’s new position will bein
orout
of the box (ifout
then it uses the previousin
position and teleports to it) - as this is just a prototype and I didn’t want the part to also glitch out in the baseplate’s floor, I add
baseplateCenter.Y
to the part’s height divided by 2.
I currently have no idea on how to calculate a perfect position and make the system comfortable and satisfying to use.
Game reference: hockey world v-slice - Roblox, say pg/me
on the chat
Thanks for all of the help and if there’s anything that isn’t clear, just ask me in the comments