I’m trying to get the angle from a part with the Mouse.Hit to place down a surface/part if the angle is equal to 180° or any but 90° since in my theory, 90° would be a wall. This would let me place down a surface/part on any desired angle within a range, except for walls.
It doesn’t have to be exactly an angle, but it could be a number that determines the rotation/angle of the hit part’s face.
I suggest instead of straight up using Mouse.Hit, but instead to use Raycasting. With Raycasting you can get the ‘Normal’ of the subject (the faces… all of them). I don’t really have much else to say but, Raycasting is the best bet for your goal.
If you want to convert the raycast normal to an angle, you can multiply it by 90, 180, or 360. For your case it is best to multiply it by 90. Eithier by multiplying it strait by 90 or Vector3.new(90,90,90)
Then I need to see if the upVector, which will come out something like this:
Contains a positive or negative 1, on its X or Z axis, signifying that it’s a wall. Therefore, in theory, I’d have to make something that checks if it’s not a wall, but if I put a bunch of or’s in my if, or I make a “for i, v in pairs()”, it will make the statement true before checking for the needed one.
I want to tell it that if the upVector is not equal to a negative or positive 1 in any vector, then run the logic.
Oh apologies, if you wanted to know if it’s a wall you can measure the angle between the worlds up vector Vector3.new(0,1,0) and the wall surface normal, if it’s perpendicular or around that range of 89 to 91 degrees it should most likely be a wall.
local function angleBetween(vector1, vector2)
return math.acos(math.clamp(vector1.Unit:Dot(vector2.Unit), -1, 1))
end
Otherwise another method to measure the wall is if the y component of the surface normal is minimal and close to zero as you noticed maybe between -0.1 and 0.1.
So… the way that I’m doing may be wrong? I mean… what I did is currently working, but I have a problem that if I’m in front of a wall, I won’t be able to place down a surface on the floor, but it at least puts it on ramps or surfaces if I’m not facing a wall.
I noticed that I may not need the Vectors, and this form works wayyyy better than the last one… but the downside is that there’s a single time that the mouse.Target and the detected part don’t coincide, which is bad. This time is if you’re looking straight at a corner. The Mouse.Target and Ray will pick 2 different parts
Even though I fixed the corner problem, I just realized that by deleting the " (upVectorX ~= 1 and upVectorZ == 0 ", it doesn’t let me place the surfaces anywhere else but floors, not ramps.