Hello,
I am wrapping up my game (My Island Resort) and I am currently experiencing a bug that I have not been able to solve. I have tried raycasting so far, and I haven’t been able to come up with anything else.
The problem is that since I am making a tycoon, the pads need to be placed on the ground so the player can easily step over them. The problem is, that the pads depend on the position of the actual item being spawned, and end up spawning in the correct positions but with weird Y’s. (As seen here: https://i.gyazo.com/424ebdc7a2e882c4159eabf040b38f67.mp4)
My script snippet that is the problem:
local cf = CFrame.new(table.unpack(ref:GetAttribute("Offset"):gsub(" ",""):split(","))) -- this is the seralized cframe converted to object space based on the plot
clone:SetPrimaryPartCFrame(self.Plot.Island.Origin.CFrame * cf:Inverse()) -- sets the place of the pad
clone:SetPrimaryPartCFrame(clone:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, math.rad(90))) -- rotates it so it isn't upside down or whatever
local params = RaycastParams.new()
params.FilterDescendantsInstances = {self.Plot.Buildings, self.Plot.Pads}
params.FilterType = Enum.RaycastFilterType.Blacklist
local result = workspace:Raycast(clone.PrimaryPart.Position, Vector3.new(0, -100, 0), params) -- this is the raycasting
if (result.Position ~= nil) then
print(result.Position)
clone:SetPrimaryPartCFrame(CFrame.new(clone.PrimaryPart.Position.X, result.Position.Y / 2 + clone.PrimaryPart.Position.Y / 2, clone.PrimaryPart.Position.Z)) -- this is my problem, the Y gets messed up or whatever and idk what happens.
clone:SetPrimaryPartCFrame(clone:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, math.rad(90))) -- this resets so i do it again
else
print('uh oh')
end
This will move the model to that position then up by exactly half its bounding height. If your rootpart is the bottom part you can swap boundingSize with that rootpart’s size.
Maybe try changing the code to match the axis that controls the thickness of the pad? For example, if it’s the x-axis that’s changing the thickness of the pad, change the code to this: