How to get the current Angular Velocity of a HingeConstraint!

This is a tutorial that is very useful for train game developers. I encountered this problem when I wanted the train to go into a sort of crusing mode, but I was unable to do so.

Today, I figured it out, and it was relatively simple.

wheel = hinge.Attachment1 -- assuming that your part1 is the wheel, if part0 is the wheel then change it
hinge.AngularVelocity = wheel.AssemblyAngularVelocity.Magnitude

this code gets the angular velocity of the wheel and then uses Magnitude to get the value in radians(i think). You can put this where you want it to cruise.

This may not work if other values are changing it at the same time, so it is reccomended that you add a boolean Attribute to detect whether the bogie(train wheel set thing) is crusing at a constant speed, so other scripts/lines do not change it.

I hope this helps anyone who needs it! :3

6 Likes

this does not work for two reasons

  1. if the vehicle is turning then the the magnitude of the angular velocity vector will increase
  2. Attachment1 is an Attachment instance, not a Part instance