I am working on a conveyor that will work even whenever its unanchored, but i need to find out what the velocity of the part that’s near the conveyor is in the direction the conveyor is moving to.
How do i detect the velocity from a part in the direction of a lookvector?
I believe the easiest way to find the velocity in the direction of the conveyor’s look vector is to use the dot product between the part’s Velocity and the conveyor’s LookVector. This will give you the part’s speed relative to the conveyor’s look vector.
e.g.
if the part is moving at 25 s/s in the opposite direction of the look vector, it returns -25,
if it’s moving 25 s/s orthogonal/perpendicular to the look vector, it returns 0.
local conveyor = -- conveyor
local part = -- part on conveyor
local relativeSpeed = part.Velocity:Dot(conveyor.LookVector)
print(relativeSpeed)
You can get the ratio of how much a part’s velocity is pointed toward the look vector by using Velocity.Unit instead of Velocity. You can multiply what you get from that by your original Velocity to get a speed relative to the look vector I believe.
local V = Part1.CFrame:VectorToObjectSpace(Part2.Velocity - Part1.Velocity)
This gives how fast Part2 is going from the perspective of Part1. -V.Z is how fast Part2 is moving along Part1s lookVector from Part1s reference frame. I.e. if -V.Z = 2, then Part2 would appear to be moving along Part1s lookVector at a speed of 2 studs per second to an observer standing on Part1. V.X and V.Y will give the speed along the RightVectors and UpVectors.