How do i see the velocity in a direction?

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?

1 Like

If you’re trying to figure out the direction a part is pointing in, just use BasePart.CFrame.lookVector.

If you are looking to find the velocity of a part, use BasePart.Velocity.

If I am mistaken, please elaborate as your wording is quite difficult to read.

2 Likes

I need the velocity in the ObjectSpace of a part.
So basically, Part is moving to (direction) with (speed)

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.

6 Likes

Also what if i wanted the part to slow down in the direction, how would i do that?

To get the relative velocity you would use:

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.

11 Likes