You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
What I want to achieve is for the transparent block to slide on top of the surface of whatever part is underneath it. -
What is the issue? Include screenshots / videos if possible!
The issue is that when I set the CanCollide Property of the transparent block to false, the block does not rebound back and forth, which is what I am going for, but the transparent block is partially inside of the part that its on top of. When I set the CanCollide Property of the transparent block to true however, the transparent block begins to rebound back and forth.
Here is a video of what happens when the CanCollide Property of the transparent block is set to false.
As you can see, the transparent block does not rebound back and forth, but it is partially within the part underneath it.
Here is another video but this time the CanCollide Property of the transparent block is set to true.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried making a ray the simulates the built in mouse.Hit.p but haven’t had much progress with figuring out how to do it effectively.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Here is the script
button = script.Parent
player = game.Players.LocalPlayer
mouse = player:GetMouse()
replicatedstorage = game:GetService("ReplicatedStorage")
userinputservice = game:GetService("UserInputService")
Run = game:GetService("RunService")
raymouseparams = RaycastParams.new()
raymouseparams.FilterType = Enum.RaycastFilterType.Whitelist
raymouseparams.FilterDescendantsInstances = {workspace}
raymouse = workspace:Raycast(mouse.UnitRay.Origin, mouse.Hit.p, raymouseparams)
--[[
endpointraymouse = raymouse.UnitRay.Origin + raymouse.UnitRay.Direction.Magnitude * raymouse.UnitRay.Direction.Unit
]]
local SpawnBlockEnabled = false
local hovering
button.MouseEnter:Connect(function()
hovering = true
button.BackgroundColor3 = Color3.fromRGB(184, 184, 184)
end)
button.MouseLeave:Connect(function()
hovering = false
button.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
end)
button.MouseButton1Click:Connect(function()
if SpawnBlockEnabled == false then
SpawnBlockEnabled = true
else if SpawnBlockEnabled == true then
SpawnBlockEnabled = false
end
end
if SpawnBlockEnabled == true then
transparentblock = replicatedstorage.PartFolder["1x1x1"]:WaitForChild("1Cube"):Clone()
transparentblock.Parent = game.Workspace
transparentblock.Transparency = .065
transparentblock.CanCollide = true
Run.Heartbeat:Connect(function()
if transparentblock then
transparentblock.Position = mouse.Hit.p
transparentblock.Orientation = Vector3.new(0, 0, 0)
end
end)
local selectionbox = Instance.new("SelectionBox")
selectionbox.Parent = transparentblock
selectionbox.Adornee = transparentblock
else if SpawnBlockEnabled == false then
transparentblock:Destroy()
end
end
end)
userinputservice.InputBegan:Connect(function(input)
if hovering == false then
if SpawnBlockEnabled == true then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local cube = replicatedstorage.PartFolder["1x1x1"]:WaitForChild("1Cube"):Clone()
cube.Parent = game.Workspace
cube.Position = mouse.Hit.p
cube.CanCollide = true
print("cube spawned")
end
end
end
end)