Hello! Is there a way to detect face 1 as a plane where the car can move and then all other faces as blocks where the car has to stop?
here an image:
Hello! Is there a way to detect face 1 as a plane where the car can move and then all other faces as blocks where the car has to stop?
here an image:
Raycasting and cframe:lookat
Make sure to check on the official page
You can cast a ray and if the normal is under a certain dot product the car can move.
local maxSlope = 0.5 --> The lower this value, the higher the ramp the car can cross
local ray = workspace:Raycast(Vector3, Vector3, params)
if ray then
if ray.Normal:Dot(Vector3.new(0, 1, 0)) < maxSlope then
print("can go up")
end
end
Vector3:Dot()
just measures how much one vector is similar to another. For example, Vector3.new(0, 0.5, 0):Dot(Vector3.new(0, 1, 0))
gives a result of 0.5
because Vector3.new(0, 0.5, 0)
is 50%
of Vector3.new(0, 1, 0)
. In the code provided, we’re measuring how vertical the raycast normal is.
https://developer.roblox.com/en-us/api-reference/datatype/Vector3
@hatespine
This brings no value, and does not help with the solution, at all. What exactly do you use CFrame.lookAt
for? Please explain in-depth.
I said cframe look at because maybe he could check if the parts cframe look at and the car cframes look at are the same then stop it if they are close enough, but of course thats more difficult than using a raycast
That doesn’t really help with the problem. CFrame.lookAt
gives you a direction from the car to the part, not the direction of the face of the part.
I mean it’s a trickier and worse solution but that’s his choice and it’s up to him
Thanks, by the way what is ray.Normal?
ray.Normal
is the normal of the face it collided with. You can think of a normal as a rotation. So, ray.Normal
is basically the rotation of the face the ray hit.