How to add a max force to assembly linear velocity?

I have a problem which i know can be solved but im just missing something in my code.

My code does (Mouse.hit.position - Pistol.Handle.Position) / duration

the problem is when i point to the sky it goes kinda out of bounds and bugs out. I still want to be able to point it to the sky but for it to have a max range and it apples force there instead of the skybox.

I guess one way would be checking if it’s greater than a certain amount.

BasePart:GetPropertyChangedSignal("AssemblyLinearVelocity"):Connect(function()
    if BasePart.AssemblyLinearVelocity.Magnitude > yourMaxAmount then --You might want to check individual elements of the Vector3, mangitude was just an example
        warn("limits for the AssemblyLinearVelocity is needed")
    end
end)



if that's for calculating direction it'll be off because that will point to the target's CFrame. You might wanna try `Camera:ScreenPointToRay()` instead and then using something like `workspace:Raycast()` with `RaycastParams`

got confused with mouse.Target

He is looking for the maximum force, not the maximum velocity. Note that force is defined as mass times acceleration (in cases where the mass is constant), meaning it’s the mass of the block multiplied by the rate of change of its velocity.

1 Like

I think that you might be interested in LinearVelocity. This would allow you to set a maximum force, as well as other things.

Linear force is constant froce which doesnt change speed. Assembly linear force is excatly what im looking for, ill try add some examples.

robloxapp-20240630-1629518.wmv (1.7 MB)

as you can see it kinda bugs out when i touch the skybox due to mouse.hit being nil. So thats why i want to add a limit.

@OptimisticSide

oops… I misread that part



This topic seems like you are trying to find a workaround to an issue with mouse.Hit. While we could calculate the acceleration and therefore the force with some maths calculations, it may be better to solve the problem from it’s root and fix the mouse.Hit issue. I’m not sure why mouse.Hit may be nil, but it may be a better option to create a ray and cast from that, or something like ApplyImpulse might do the job.

Ill try apply impulse and let you know if it works thanks.

1 Like

Tried apply impulse and it didnt seem to solve my problem unfortunately ill keep searching around and try to find something else.