Ok i just made a simple bear trap placement system, but im using terrain so when u place the trap It kinda like clips through the terrain(I’ll show a picture). How would I fix it clipping through the ground? Could I like shoot a ray into the ground, and like re-align the bear trap with the ground under it?
What is the best way to Re-Align The bear trap with the floor?
so bassically you need to find the normal (aka the 3d version of slope) of the terrain directly under your part. you can do this by just sending a raycast down from the part and getting the results normal. for example,
local rayOrigin = partposition + Vector3.new(0, 5, 0) -- move the position up by a bit just in case the part is clipped in the ground
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {part} -- so it doesnt hit itself
rayParams.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(rayOrigin, Vector3.new(0, -100, 0), rayParams)
keep in mind that this assumes that your bear trap part is facing up (you can check the orientation of the part by right clicking on the part and clicking “show orientatrion indicator”)
ohh, thank you I was trying to multiply it by math.Angles(90,0,0). Is that What math.rad does just multiply it according to the parts orientation not the worlds?
math.rad changes degrees to radians, because that’s what CFrame.Angles uses, if you put in degrees it’ll be completely different from the correct angles
Oh ok thank you so much for helping me understand that. I wish I could give a solution to both of y’all, but I can’t. I’m gonna give it to slobbery, because he showed me how to do it, but thank you so much Eli for making it rotate properly.
Here is how the finished product works
Thank you guys so much!
EDIT: I don’t have animations yet, but when I add them I think it will look really good!