How to limit the velocity of a flying vehicle

  1. What do you want to achieve? Keep it simple and clear!

I am designing a helicopter for my place and then wanna release it as a free model, as I feel there are no simple helicopters that are scripted up to modern standards, without the use of hopperbin tools or legacy bodymovers or a super advanced system to simulate aerodynamics. I want to use as much of the roblox physics engine as I can.

My helicopter uses three VectorForces to roll left and right, spin in place and pitch the nose up and down. A fourth VectorForce on the bottom of the helicopter is the thrust. Throttling up sets the thrust’s force value. Pitch and roll changes the orientation of the thrust’s attachment, so the craft can move.

  1. What is the issue? Include screenshots / videos if possible!

I’m not sure of a simple way to limit the overall speed of the vehicle in any direction. Because VectorForces are continuous, the speed of the helicopter quickly gets out of hand and seems to double when tilting or rolling. I am not sure how to approach fixing the issue in a simple way.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have searched the dev forums for the past few days to see if anyone has tried what I have, and I haven’t been able to think through a good solution. The last solution I have tried is checking if the X, Y or Z AssemblyLinearVelocity of the ‘base’ part that everything is attached to, is above a certain value and then resetting it to that value, but that results in jittery movement that does not feel correct and is still not correctly limited.

function limit(vec)
    local x = vec.X
    local y = vec.Y
    local z = vec.Z
    if x > 100 then
        vel = 100
    end
    -- etc. this checking six more times for positive and negative values
    return Vector3.new(x, y, z)
end

-- and then in the function I've attached to Runservice.Stepped
Base.AssemblyLinearVelocity = limit(Base.AssemblyLinearVelocity)

I would be happy to post the full script if this isn’t enough to zero in on what I’m trying to achieve. I feel like I’m missing something important.

Thanks all!

You can’t use the velocity from a stepped time frame because that’s before the physics happens. Get the velocity from a heartbeat time frame where physics has already happened.

I’d completely forgotten about that! thank you for pointing it out. the script even works just as before when not hooked up to Stepped but Heartbeat.

Since velocities of objects derive from vector.zero you can check the magnitude (Base.AssemblyLinearVelocity.Magnitude) of your velocity. And to limit the velocity when it reaches a certain threshold, you can get the unit of the vector such as: Base.AssemblyLinearVelocity.Unit * MaxMagnitude (In this case you’re limiting it to 100 studs).

Your current set up blocks off velocity in a cube like form, while checking the magnitude of the velocity will make it into a sphere which is more common in movement.

1 Like

You should use what @Kitsomia is saying with how you should do it. Using the same method she said but using a function that limits it:

Base.AssemblyLinearVelocity.Unit * math.min(Base.AssemblyLinearVelocity.Magnitude,100) 
2 Likes

Thank you @Kitsomia and @rottendogDkR ! the explanation and code make a lot of sense and it works exactly how I expected it to. so now, I can work on making it smoother.