A character in motion will stay in motion unless a force is applied to it

Hi, I am not sure in which category this topic should be in, but I really want to know, is there a way for a character in motion to stay in motion unless they actually collide with a part to stop them from completing the jump. Basically I want it be where if a character is jumping while going forward, they keep going forward and they can’t switch directions or stop moving forward in the middle of the jump, is this possible, if so, I would love to know how to do that.

2 Likes

You’ll need to send the Humanoid into a Physics-like state, similar to a PlatformStand or Sitting state.

A HumanoidStateType that sticks out here is the Flying type, which will disable all of the Humanoid physical constraints, but will still detect landing as if Freefalling.

To do this, we can disable the FreeFall state (which will usually eat the inertia) and replace it with a Flying state when the FloorMaterial is nil.

    -- The Freefall state zeroes out velocity, we want our jumps to maintain some inertia, so
    -- we're going to disable it and replace the behavior ourselves
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)

    humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(
        function()
            if humanoid.FloorMaterial == Enum.Material.Air then
                -- As we have disabled Freefall, we want to use the Flying state when the player
                -- is in the air
                humanoid:ChangeState(Enum.HumanoidStateType.Flying)
            end
        end
    )

Since Flying has the property to detect landing built in, we don’t have to worry about re-transitioning back to Running manually.

Though we are disabling all physical forces, the character will start to rotate in mid air if it collides with an object. You’ll likely want to manually handle the humanoid’s orientation while it’s in the air with an AlignOrientation.

16 Likes

thanks a lot man I actually never knew about this thanks so much another day of learning, also AlignOrientation I was looking at it in the dev hub, but I don’t know how to implement that into a character, do I add an invisible part in front of the character and adding the constraints so that they both have similar rotation?

What I’d usually do is parent the AlignOrientation within the character, Attachment0 is one of the Root attachments from the character, and Attachment1 is an attachment in Terrain (though some may think this is messy)

Alternatively you may create an anchored, unconstrained part within the character to hold these attachments so cleanup is easier/essentially free.

Either way, yeah you’ll want to just have it so Attachment1 is the orientation you’re shooting for, either the Humaniod.Torso.CFrame.LookVector at the time of jump or responsive to Humanoid.MoveDirection or some third example.

3 Likes

What about humanoid.AutoRotate when a player presses spacebar, wouldn’t that work, that would save a lot more time I would think would you think that would work to disable the AutoRotate(false) when spacebar is pressed and when player has landed, AutoRotate is set to true

AutoRotate won’t help much in this case because we’re in HumanoidStateType.Flying which disables all physical forces on the Humanoid while we’re in this state, including the Gyro controls that usually help keep the Humanoid upright and facing the intended direction, which AutoRotate influences.

AutoRotate can turn off this Gyro-locking behavior when set to False in a non-Physics HumanoidStateType, but setting AutoRotate to True in a Physics HumaniodStateType (such as PlatformStanding, Sitting, Flying, Physics, etc) will have no effect.

2 Likes

Yeah I just tried to do that and didn’t work, and now I am learning about AlignOrientation and I am having some troubles to just test how it works because I placed 2 parts, I added an attachment to both of them and added an AlignOrientation in one of them and changed the attachment 1 and 0 and I am getting no results at the moment.

  1. Make sure the Part with Attachment0 isn’t Anchored. This will prevent physical forces from influencing the Part
  2. Try setting AlignOrientation.RigidityEnabled to True to make sure it’s not a maxTorque issue. You can set it to False if this works and adjust the maxTorque as needed once you know its working.
  3. Make sure you try to rotate the Part with Attachment1, either with the Rotate tool or some other external force. Just to make sure you’re not seeing anything because the Attachments are already aligned!

If you’re still having troubles, feel free to send your demo here as an .rbxl and I’m sure either myself or someone else can determine why you’re not seeing what you’re expecting.

1 Like

alignconstraints.rbxm (3.3 KB)

I have tried everything you said, and when I rotate the part(both parts) they wouldn’t allow me to rotate

Seems to be working fine for me. Looks like you’ve done everything correctly.

I’ve gone ahead and inserted your model as-is, ran the simulation, and was able to turn the reference part with the Rotate tool which influenced the target part

1 Like

It seems to be my rotate tool is locked, even after i do ctrl + L it doesn’t work I did exactly everything u did, I might be asking for too much but how would the script look like if I were to implement this into the jump?

Question, how would I keep letting the player move, jump and be normal, but rotate in all axis. As in they can still move, but they just won’t be standing up. Almost like a ragdoll. The reason why is because in my game you’re a circle, but when the circle moves, it doesn’t roll.