I’m trying to create a disorientation effect, where when moving the character feels disoriented or dizzy, occasionally going in the wrong direction when trying to walk. Would it simply be enough to do humanoid:MoveTo in the opposite direction? Would that not get overwritten almost immediately by user input?
To create a disorientation effect in Lua, you can override the user input temporarily by using a variable to store the direction the character should move in. Here’s a basic example to get you started:
-- Get the Humanoid and character
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local character = humanoid.Parent
-- Set up disorientation effect variables
local disorienting = false -- Tracks if the character should be disoriented
local disorientationTime = 2 -- The duration of the disorientation effect in seconds
local disorientationDelay = 5 -- The time between each disorientation effect in seconds
-- Function to temporarily change the character's movement
local function DisorientCharacter()
if disorienting then return end -- Prevent overlapping disorientations
-- Set the character's movement to the opposite direction
local originalDirection = character.HumanoidRootPart.CFrame.LookVector
local disorientedDirection = -originalDirection
humanoid:MoveTo(character.HumanoidRootPart.Position + (disorientedDirection * 5)) -- Adjust the "5" for desired distance
disorienting = true
wait(disorientationTime)
disorienting = false
end
-- Apply the disorientation effect periodically
while true do
wait(disorientationDelay)
DisorientCharacter()
end
In this script, we first grab the Humanoid and character objects. We then set up the disorientation effect variables such as disorienting to track if the character is currently disoriented, disorientationTime to set the duration of the disorientation effect, and disorientationDelay to set the time between each disorientation effect.
The DisorientCharacter function is responsible for temporarily changing the character’s movement. It first checks if the character is already disoriented to prevent overlapping disorientations. Then it retrieves the original movement direction and calculates the opposite direction. Using humanoid:MoveTo, we move the character in the opposite direction for a desired distance (adjust the “5” value as needed). We wait for the disorientationTime, indicating the duration of the disorientation effect, before resetting the disorienting variable.
Lastly, we create a loop that periodically applies the disorientation effect using disorientationDelay. This ensures that the effect will be applied at regular intervals.
Remember to adjust the distances and timings according to your desired effect. Feel free to modify the script as needed.