How to get a parts velocity relative to that part?

  1. What do you want to achieve?
    self explanatory title but, currently with my code i can only print out AssemblyLinearVelocity relative to the world.

    while readoutvelocity == true do
    	print(script.Parent.UpperTorso.AssemblyLinearVelocity)
    	task.wait(1)
    end
    

    For my code to be easier, how would go about changing this to be relative to the part?

  2. What solutions have you tried so far?
    i looked on youtube and devforum but they both think im saying something else

this basically explains what i want the ‘AssemblyLinearVelocity’, or atleast a variable after conversion, to look like. the velocity doesnt change, but the variable describing the velocity changes because the part rotated.
image
(purple is top face and green is front face)

i also wasnt really sure if this should be in Scripting Support or Code Review since i already technically have my own code, if i got it into the wrong category, sorry, lmk

5 Likes

Multiply AssemblyLinearVelocity by the direction you want it to be relative to

2 Likes

so multiply it by the LookVector…? i dont really want a specific direction more so that i want the velocity to be relative to the part

1 Like

Not sure what you mean relative to the part, but have you tried maybe using AssemblyAngularVelocity too?

1 Like

i mean like, since im trying to use this for a speedlimit system, if i was looking forward and going 50 studs a second in that direction, i wouldnt get pushed any faster, but if i looked to the right, i would start moving faster again.

1 Like

Oh that’s easy then, just get the magnitude to get the total speed and use that as a speed limit

1 Like

sadly i would have done that but i have to have speedlimits for going backwards, left and right, and up and down too. so in one moment, i might be going too fast forward to be able to continue accelerating forward, but i should still be able to move in any other direction.

1 Like

How are you detecting the inputs for forwards, backwards, left and right?

1 Like

with InputService…? im not sure what you mean?

1 Like

i think this may work to do what i want, but do you think it would make the Vector3 change by multiplying with the torso’s LookVector?

1 Like

Asked this because there are a lot of different ways to detect input from the player, I like to use the move vector for example.

2 Likes

no, you use the output to adjust the speed only

1 Like

oh, ok then, how else would i do it then?

1 Like

I mean, yeah it would make the vector3 change if you multiply it by the lookvector. That’s why I asked how you’re detecting front/back/left/right movement because you could just use that as a “direction” constant and from there adjust the speed

1 Like

You should try a CFrame function like VectorToObjectSpace.

2 Likes

Yeah, I just did this a couple days ago, I think this is what you want:

		local objvel = part.CFrame:VectorToObjectSpace(part.Velocity)
	    print("objectvelocity Z:", objvel.Z)

If that part is a part, the print statement will give you the relative velocity of that part

5 Likes

ooh that sounds promising, i knew of ObjectSpace and WorldSpace for cframes but not for vectors

that looks exactly like it!! let me check if it is!

i got good news and bad news, so i’ll say it at once; it DOES WORK, but only for forwards and backwards… i still need 2 variables, one for left and right, and one for up and down, but if im not wrong, i can do this by multiplying the part.CFrame with a CFrame.Angles one, right?

sorry for the late reply by the way i had to go to sleep

CRAP sorry ignore this i just reread it and just realised it has a .Z that i can remove for what i want LOL

1 Like