Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i compare a CFrame.Position to a Value?

Asked by
DBoi941 57
4 years ago

I am not sure how to compare CFrame.Position to a Value. I have tried this and it does not work. Any help in leading me in the right direction would be great. Thanks.

local rock = script.Parent.Parent.Stand4
if rock.CFrame.Position == Vector3(375.839966, -64.2299347, 694.550415) then

end
1
if CF.Position == Vector3.new(...) then crywink 419 — 4y

1 answer

Log in to vote
2
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

To create a vector3, you need to do vector3.new() Theres two ways you can compare vector3's:

v3 = Vector3.new(375.839966, -64.2299347, 694.550415)
local rock = script.Parent.Parent.Stand4
rockPos = rock.CFrame.Position

--you can compare the vector3 values like this:
if(rockPos == v3)then
    print("yes")
else
    print("no")
end

--or you could compare the individual values:
if(rockPos.X == v3.X and rockPos.Y == v3.Y and rockPos.Z == v3.Z)then
    print("yes")
else
    print("no")
end

don't rlly need to do option 2 but its a way of doing things

0
Thank you for all the details. DBoi941 57 — 4y
1
You should never do this. Ever. Floating point comparisons with == are the recipe for really hard to diagnose, hard to repro bugs. EmilyBendsSpace 1025 — 4y
1
You should always compare with something like (CFrame.Position - otherPos).Magnitude < 0.001, where the exact tolerance value (here 0.001) depends on how you're moving the parts and how close counts as equal for your application. EmilyBendsSpace 1025 — 4y
1
If you don't think this is true, execute this from Studio's command line: a=0.1 b=0.7 print(a*7,b,a*7==b) EmilyBendsSpace 1025 — 4y
0
thank you I didn't know that royaltoe 5144 — 4y
Ad

Answer this question