Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What does -distance/2 mean in sizing your part?

After looking into a roblox tutorial for raycasting, I have come across something quite puzzling(I am not very good with math,that's why I ask). The distance value in the beams CFrame is negative, and divided by 2, can someone tell me why each one of those two things are?

beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)

Larger chunk of script:

local distance = (tool.Handle.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)

4 comments

0

it's making distance a negative number and dividing it by 2

0

I know that silly, what i'm trying to figure out is what effect it will have on the ray

0

play with it. Change the 2 to different numbers. Instead of dividing, multiply, add, or subtract it to see the effect it has.

0

I wouldn't be here if I hadnt already tried that, from what I can tell undoing the negative has no effect, and I think that removing the 2 makes it shorter

1 answer

✓ Accepted answer

If you multiply a CFrame and it's inverse then you get CFrame.new() back every time. Also the script is getting the Vector3 values from the ".p" and they are (0.3, 0.3 and distance) which looks like it's the diameter of the beam. So its established that the beam.CFrame = CFrame.new (position) *(multiplied) by CFrame.new (/2) or half the distance from the position. For position, a negative is usually only say 180 degrees from it's respective positive integer. Did this make any sense? It's late here. Please correct me if I misinterpreted your question.

1 comment

0

When you say get back? You don't mean like a return do you?

This discussion is preserved as it was. New answers, comments, and votes are closed.