This is sort of like a sequel to my previous post. Also I’m not a certified expert at RaycastParams.
I’ve been struggling with this problem for a while now and it’s kinda bugging me. So from the last post, I actually needed help on “setting up a barrier for the player’s builds.” Now you don’t have to go back to it, but since I wanted to create a Region3, it requires a region.
Everytime I hover over the part in build mode, the block would just go above the region. Like so:
I couldn’t add the mouse inside of the picture, so I just drew it out
I’ve tried numerous ways to end this problem. One of them is:
--Local script
local castParams = RaycastParams.new()
castParams.FilterDescendantsInstances = { player.Character, chosenClone, workspace.Regions:GetChildren()}
I’ve also looked up ways for parts to get ignored by rays, but it still didn’t help.
2 Likes
are you using cframes to move the part, or are you changing its position? i believe that changing position still respects collision physics so your ray might be hitting the desired point but the green block is being moved on top of the grey region
1 Like
workspace.Regions:GetChildren() is a table. It wont search a 2nd level table I don’t believe. You can try table.unpack(workspace.Regions:GetChildren()) or just workspace.Regions I think both should work.
1 Like
I’m using position, not CFrame.
1 Like
I tried table.unpack(workspace.Regions:GetChildren()) before. It didn’t work.
1 Like
try using cframes to position the part then
1 Like
I use :MoveTo since I’m using models.
Edit: how can I move a model with CFrame?
1 Like
model:SetPrimaryPartCFrame()
set the primary part of the model first
2 Likes
It works, but it just glitches into the ground and everytime I move the mouse it resets the rotation when you move it with R.
Edit: I can avoid the last part I said since I can multiply the CFrame.
2 Likes
yeah thats expected because cframe includes both orientation and position.
first of all to stop it from glitching into the ground, you have to take into account the position of the PrimaryPart with respect to the bottom of the rest of the model. just add the relative position to the CFrame of your raycast or whatever
1 Like
I actually don’t see the model. Is there something wrong with my code?
chosenClone:SetPrimaryPartCFrame(chosenClone:GetPrimaryPartCFrame() * CFrame.new(pos(result.Position + result.Normal * 0, 0.1)))
1 Like
whats the code supposed to do? im not sure what you wrote here tbh
1 Like
ChosenClone is the mode you’re moving. I used :SetPrimaryPartCFrame to set the CFrame, but when I do GetPrimaryPartCFrame it doesn’t work as expected.
1 Like
what is the cframe that you multiplied to the GetPrimaryPartCFrame()
1 Like
That’s to position the model to where the mouse is.
1 Like
oh lol the reason you cant see the part is because you have an infinite loop of adding to the position of the part. its probably in outer space after 2 seconds lol
for now just set the CFrame of the model to the mouse position, relative to the orientation of the surface.
local newCFrame = CFrame.lookAt(result.Position, result.Position + result.Normal)
ChosenClone:SetPrimaryPartCFrame(newCFrame)
the orientation is gonna be really messed up but it should put it in the position of the mouse. try it and see if it works, then i can help you orient it correctly
1 Like
It just faces the ground. Also, everytime I move the rotation and move the mouse, it does the same thing. 
1 Like
yeah i know lol, thats what is supposed to happen at this point.
how do you have the rotations set up? do you have functions set to the R and T key or something to rotate it?
1 Like
Everytime I press R, it does this:
function input(keycode, gps)
if keycode.KeyCode == Enum.KeyCode.R then
if enabled == true then
chosenClone:SetPrimaryPartCFrame(chosenClone:GetPrimaryPartCFrame() * CFrame.Angles(0,math.pi/2,0))
end
end
end
1 Like
ok thats good, you just have to rewrite it a bit since we are constantly resetting the cframe everytime the mouse updates position.
instead of the R key directly changing the position, have it update a rotation CFrame, which then will be used in the constantly updated CFrame:
local rotation = CFrame.Angles(0,0,0)
function input(keycode, gps)
if keycode.KeyCode == Enum.KeyCode.R then
if enabled == true then
rotation = rotation*CFrame.Angles(0,math.pi/2,0))
end
end
end
now change what we had before to this:
local newCFrame = CFrame.lookAt(result.Position, result.Position + result.Normal)*rotation
ChosenClone:SetPrimaryPartCFrame(newCFrame)
now the rotation should save
1 Like