I have a BasePart with zero friction that I want to inherit the velocity of the BaseParts beneath it. When it comes to linear velocity, all I have to do is add the velocities of the BaseParts, then add whatever additional velocity I want on top of it in order to achieve my goal.
function FixedUpdate(_, deltaTime) --connected to RunService.Stepped
local baseVelocity = Vector3.new()
for _, part in pairs(GroundedParts) do
if part.CanCollide then
baseVelocity = baseVelocity + part.Velocity --there could be a better way to handle velocity by getting the average of all of the velocities but i'm too lazy to do that right now
end
end
local additionalVelocity = Vector3.new(10, 0, 0)
FinalVelocity = additionalVelocity + baseVelocity
Movement.Velocity = FinalVelocity --Movement is a BodyVelocity parented to the Part
end
I can also do the same thing with angular velocity and rotations, although I use a BodyGyro instead of a BodyAngularVelocity to lock the X and Z axes of rotation and make it easier to make the part face at an angle.
function FixedUpdate(_, deltaTime) --same function as before except I removed all of the unnecessary parts so this is easier on the eyes I guess
local baseRotVelocity = Vector3.new()
for _, part in pairs(GroundedParts) do
if part.CanCollide then
baseRotVelocity = baseRotVelocity + part.RotVelocity
end
end
FinalRotation = FinalRotation * cfa(0, baseRotVelocity.Y * deltaTime, 0)
Rotation.CFrame = FinalRotation
end
However, I face an issue when trying to convert the angular velocity into linear velocity. No matter what I try, the rotation always seems slower or faster than the linear velocity, destroying the effect. The only thing I've seem to have gotten correct is how to calculate the direction of the linear velocity, which is perpendicular to the vector between the part that inherits the angular velocity and the part that has the angular velocity.
local function perpendicular(v)
return Vector3.new(v.Z, 0, -v.X) --roblox apparently has a "right-handed" cartesian coordinate system so i have to do this which is just a negated form of Vector3.new(-v.Z, 0, v.X)
end
local radius = ((Character.Position - part.Position) * Vector3.new(1, 0, 1)).Unit
local tangent = perpendicular(radius).Unit --there could be a better way to do this using the cross product between the y axis and the radius but i'm just going to leave it like this for now
How am I supposed to calculate the magnitude to multiply the direction by? I know that it somehow involves the angular velocity itself (which is why nothing spins when a part has an angular velocity of 0, 0, 0), but what else should I throw in there, and why?
NOTE: sorry for the bad grammar it's almost 8 pm


3 comments
use a camshaft
that's an oddly specific problem, what exactly are you trying to achieve with this
just thought of something to answer this problem