Fixing Land Mechanic

Edit: Sorry guys! Im stupid… I use “SmoothShiftLock” Module which is a remake of the roblox shiftlock. I have found a solution but that stands in my way. Haha (Im so dumb)

Hello!

I made this land mechanic. Its supposed to detect when you fall from a certain threshold distance and trigger an animation, some effects and whatnot.

However, there is still one problem.

Video Examples:


You can turn your character while this mechanic plays out. Anyone know how to stop that?

I want it so even if you turn your camera. The characters keeps going in the direction they landed.

This is the code that I use.

local LandModule = {}

--//Services
local Players = game:GetService("Players")
local DebrisService = game:GetService("Debris")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local StarterPlayer = game:GetService("StarterPlayer")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

--//Global Variables
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")
local Animator = Humanoid:WaitForChild("Animator")

local Camera = workspace.CurrentCamera

--//Resources
local ReplicatedAssets = ReplicatedStorage.Assets

local Animations = ReplicatedAssets.Animations
local SFX = ReplicatedAssets.SFX
local VFX = ReplicatedAssets.Effects

--//Modules
local Modules = ReplicatedStorage.Modules

local GlobalModule = require(Modules.Effects.Global)
local ContextUtility = require(script.Parent.Parent.Parent.Utility.Context)

local MaidModule = require(Modules.Utility.Cleaners.Maid)
local Maid = MaidModule.new()


--//Animations
local MovementAnimations = Animations.Movement
local MiscMovementAnimations = MovementAnimations.Misc

local LandAnimation = Animator:LoadAnimation(MiscMovementAnimations.SoftLand)
LandAnimation.Priority = Enum.AnimationPriority.Action4


--//Sounds
local MovementSfx = SFX.Movement

local LandSounds = MovementSfx.Lands

local LandSound = LandSounds.SoftLand

--//UtilityFunctions
local function GlobalModuleEffects(Magnitude,Roughness,DurationBetweenStun,Anchored,HighlightDelay,HightlightTime,BlurDelay,BlurTime)
	
	Maid:GiveTask(task.spawn(function()

		Maid:GiveTask(task.spawn(function()
			GlobalModule.Highlight(HighlightDelay,HightlightTime,Character)
			GlobalModule.Blur(BlurDelay,BlurTime,Character)
		end))

	end))
	
end

local function BodyVelocity(Power,Duration)
	

	local RootVector = RootPart.CFrame.LookVector

	local BodyVelocity = Instance.new("BodyVelocity", RootPart)
	BodyVelocity.MaxForce = Vector3.new(0,0,math.huge)
	BodyVelocity.P = 1000
	BodyVelocity.Velocity = CFrame.new(RootPart.Position,RootPart.Position + Vector3.new(RootVector.X,0,RootVector.Z)).LookVector * Power
	
	DebrisService:AddItem(BodyVelocity,Duration)
	
end

--//ModuleFunctions
function LandModule.Land()
	
	GlobalModuleEffects(4,4,1,false,0,.5,0,.7)
	
	LandAnimation:Play()
	LandSound:Play()
	
	BodyVelocity(25,.5)
	
	ContextUtility.FreezeMovement(0.7)
	
	Maid:GiveTask(task.spawn(function()
		
		local SavedWalkSpeed = Humanoid.WalkSpeed
		Humanoid.WalkSpeed = 0
		Humanoid.AutoRotate = false
		
		LandAnimation.Stopped:Connect(function()
			Humanoid.WalkSpeed = SavedWalkSpeed
			Humanoid.AutoRotate = true
		end)

		
	end))
	
end


return LandModule

Thank you!

2 Likes

When landing set Humanoid.AutoRotate to false and when finished set it to true again

I already do that, But it seems like the issue persists

	Maid:GiveTask(task.spawn(function()
		
		local SavedWalkSpeed = Humanoid.WalkSpeed
		Humanoid.WalkSpeed = 0
		Humanoid.AutoRotate = false
		
		LandAnimation.Stopped:Connect(function()
			Humanoid.WalkSpeed = SavedWalkSpeed
			Humanoid.AutoRotate = true
		end)

		
	end))

Not sure but that’s would already fix the problem.

hm… Is there any other way to force the character to not “AutoRotate”

Your only way is to lock the HumanoidRootPart from rotating and unlock it when the animation is done (using math)

any knowledge on how to do that? Im honestly clueless lol

One tool you can use is a function like this which disables movement controls temporarily.

local ContextActionService = game:GetService("ContextActionService")

local function FreezeMovement(duration)
	local FREEZE_ACTION = "freezeMovement"
	Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	--stopanims()
	ContextActionService:BindAction(
		FREEZE_ACTION,
		function()
			return Enum.ContextActionResult.Sink -- need to explicitly return this
		end,
		false,
		unpack(Enum.PlayerActions:GetEnumItems())
	)
	task.delay(duration,function()
		--h.Parent=Player.Character.Humanoid
		ContextActionService:UnbindAction(FREEZE_ACTION)
	end)
end

I use this method after much research. I think it is the best way to temporarily disable controls for state transitions.

Magnus.

The savior of all things Roblox.

DUDE I love you! Thank you for your contributions to the community as well as your support in these forums.

Anyways, Ill try that out and get back to you. Thank you!

1 Like

Okay so, It DOES NOT work but I was wondering…

I meant to disable the turning of the character, I already handle the character not being able to change the direction of the land. Its just that they can turn around on the x axis.

I Need a way to lock the rootpart or something like that in place. Just something that would stop the character from turning around while the land animation is playing.

1 Like

Can we have the full unedited script?

yea sure. ill put it in the original post.

Its there now. If you need any more please ask.

Some other things you can try is

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)--disable running temporarily
Animation.Stopped:Wait()
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)

Disabling evaluate state machine temporarily.

Humanoid.EvaluateStateMachine=false--do not evaluate humanoid states until it is true
Humanoid.EvaluateStateMachine=true

Alternatively, you can use a bodygyro with set with the cframe. In this example it is set so you cannot turn on the Y axis but you can turn on the x and z axis, I use this method for a special resting state.

local gyro=Instance.new("BodyGyro")
gyro.CFrame=HumanoidRootPart.CFrame
gyro.MaxTorque=Vector3.new(0,math.huge,0)
gyro.Parent=HumanoidRootPart

Man! none of these work.

Ill look to some more resources on the Roblox list thingy idek

Oh wait! so uhm… I use the “Smoothshiftlock” Module. It replaces shiftlock with a much better version.

Might be why, It sets the humanoid autorotate itself. So ill try to figure that out.

1 Like

Yea. I fixed it by using the “ToggleShiftLock” Function inside of SmoothShiftLock.

Not the best solution but im too lazy to figure out better right now

1 Like