Good day all!, I’m having an issue with calculating the acceleration of a part aka mimicking what an Accelerometer would do. I need to check the acceleration of a part more so a rocket or even a train to be able to then use this data for a PID Controller to control various useful systems.
PID stuff etc I have that all covered but calculating what should be simple is proving very flinky and Im finding the Vector3 values returned are rapidly changing with absurd numbers.
My issue is that I calculate the Acceleration with:
local lastVelocity = script.Part.AssemblyLinearVelocity
local RunService = game["Run Service"]
RunService.Stepped:Connect(function(_, delta)
local Acceleration = (script.Part.AssemblyLinearVelocity - lastVelocity) / delta
lastVelocity = script.Part.AssemblyLinearVelocity
end)
I get values that fluctuate extremely largely and seemingly inaccurate. I’m using a PID controller to then try to maintain a specfic Acceleration of which its applying force in said direction using a VectorForce constraint.
Mainly I’m just trying to figure out if there is any better or accurate ways of calculating acceleration like an Accelerometer would. Thanks!
@kckhem Is there anyway for us to get instantaneous Acceleration without all the noise that its exposed to rendering it useless when we use: Acceleration = (currentvelocity - lastvelocity) / deltatime
Having an Acceleration value like Velocity or some sorts that just shows the Acceleration is highly useful unless there is someone to accurately replicate an Accelerometer sensor to measure Acceleration.
Having an accurate Acceleration readout would help understand the physics of vehicles etc much better than current, one would be able to use the data to develop advanced systems like Vehicle autopilot etc and develop proper braking curves etc plus character development.
Example of noisy acceleration no matter the method of lerp, smoothdamp etc:
If the script is serverside, double check if the part you’re measuring is owned by the server or client. A difference in networkownership could be causing the fluctuations.
Yeah which is client side. Im not sure one can get rid of the noise so much regardless of client or server it just reduces a bit on the client vs server.
I see, might have to attempt that or shelve it for now till there is possibly a better way to accurately calculate it with much less noise as its really needed for a PID controller
At the moment we do not provide acceleration (or force and torque) data, but I can see how it would be useful. Thanks for this suggestion, we will think about ways to expose this information.