Dizzy/Drunk Walking

I am trying to make the player walk in a wavy dizzy/drunk direction but I cannot get Humanoid:Move() or Player:Move() to work at all! Here is what I currently have, trying to recreate basic movement by disabling the default control system.

local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")

local humanoid = Players.LocalPlayer.Character.Humanoid

local function dizzyForward()
	print("moving forward")
	humanoid:Move(Vector3.new(0,0,-1), false)
end

local function dizzyBackward()
	print("moving backward")
	humanoid:Move(Vector3.new(0,0,1), false)
end

local function dizzyLeft()
	print("moving left")
	humanoid:Move(Vector3.new(1,0,0), false)
end

local function dizzyRight()
	print("moving right")
	humanoid:Move(Vector3.new(-1,0,0), false)
end


local FROZEN_ACTION_KEY = "freezeMovement"

ContextActionService:BindActionAtPriority(
    FROZEN_ACTION_KEY,
    function() 
        return Enum.ContextActionResult.Sink
    end,
    false,
    Enum.ContextActionPriority.High.Value,
    unpack(Enum.PlayerActions:GetEnumItems())
)

ContextActionService:BindActionAtPriority("Forward", dizzyForward, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.W, Enum.KeyCode.Up)
ContextActionService:BindActionAtPriority("Backward", dizzyBackward, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.S, Enum.KeyCode.Down)
ContextActionService:BindActionAtPriority("StrafeLeft", dizzyLeft, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.A, Enum.KeyCode.Left)
ContextActionService:BindActionAtPriority("StrafeRight", dizzyRight, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.D, Enum.KeyCode.Right)

local function stop()
	print("enabling controls again")
	ContextActionService:UnbindAction(FROZEN_ACTION_KEY)
end

ContextActionService:BindActionAtPriority("end", stop, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.Y)

I have also tried a simpler version, without directly disabling all player input

local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")

local humanoid = Players.LocalPlayer.Character.Humanoid

local function dizzyForward()
	print("moving forward")
	humanoid:Move(Vector3.new(0,0,-1), false)
end

local function dizzyBackward()
	print("moving backward")
	humanoid:Move(Vector3.new(0,0,1), false)
end

local function dizzyLeft()
	print("moving left")
	humanoid:Move(Vector3.new(1,0,0), false)
end

local function dizzyRight()
	print("moving right")
	humanoid:Move(Vector3.new(-1,0,0), false)
end


ContextActionService:BindAction("Forward", dizzyForward, false, Enum.KeyCode.W, Enum.KeyCode.Up)
ContextActionService:BindAction("Backward", dizzyBackward, false, Enum.KeyCode.S, Enum.KeyCode.Down)
ContextActionService:BindAction("StrafeLeft", dizzyLeft, false, Enum.KeyCode.A, Enum.KeyCode.Left)
ContextActionService:BindAction("StrafeRight", dizzyRight, false, Enum.KeyCode.D, Enum.KeyCode.Right)

Both of these scripts only execute the print statements with no movement.

I have had no luck looking at previous posts relating to :Move() so would appreciate any help!

1 Like

Hi so I am not a scripter so I am not sure but I do want to say that if you do a game were you get drunk it will be against the TOS.

2 Likes

Hi, thanks I wasn’t aware but that wasn’t my intention anyways - I was just trying to put a visual to my intentions. I’m just trying to achieve the wavy walking.

2 Likes

Ok that’s fine. The reason it would be against the TOS is because it’s a over 18 product and not really classed as child friendly.

3 Likes

I believe that as long as its not explicitly stating that it is alcohol, it is perfectly fine to make a drunk/dizzy effect.

So he should be in the clear if he just makes a dizzy effect/drunk effect. Just dont state its an alcohol or something similar. You can maybe call it a dizzy potion.

3 Likes

It would be an effect that you can get from being hit from a weapon, as if dazed, so I’m not worried about that, just on how to get :Move() to work.

You don’t have to specifically making it drunk in the game. You could be creative, maybe drink a potion and start walking weird.

Anyway to help out, you will probably save time and effort by animating the walk instead of scripting it. Just create a really wobbly walking animation and use that.

1 Like

Humanoid:Move() must be used in a function that is bound to fire at render step or other quick-firing loops. It needs to be fired consecutively to get any movement because the default control scripts will overwrite the player’s movement every frame. As an example, I edited your code a bit. The way I implemented it was pretty unoptimized and unconventional, but it gets the player moving. Note how I added a RunService.RenderStepped function underneath the local variables.

local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local rs = game:GetService("RunService")

local humanoid = Players.LocalPlayer.Character.Humanoid
local direction = Vector3.new(0,0,0)

rs.RenderStepped:Connect(function()
	humanoid:Move(direction, false)
end)

local function dizzyForward(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		print("moving forward")
		direction = Vector3.new(0,0,-1)
	elseif inputState == Enum.UserInputState.End then
		direction = Vector3.new(0,0,0)
	end
	
end

local function dizzyBackward(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		print("moving backward")
		direction = Vector3.new(0,0,1)
	elseif inputState == Enum.UserInputState.End then
		direction = Vector3.new(0,0,0)
	end
end

local function dizzyLeft(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		print("moving left")
		direction = Vector3.new(-1,0,0)
	elseif inputState == Enum.UserInputState.End then
		direction = Vector3.new(0,0,0)
	end
end

local function dizzyRight(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		print("moving right")
		direction = Vector3.new(1,0,0)
	elseif inputState == Enum.UserInputState.End then
		direction = Vector3.new(0,0,0)
	end
end


local FROZEN_ACTION_KEY = "freezeMovement"

ContextActionService:BindActionAtPriority(
    FROZEN_ACTION_KEY,
    function() 
        return Enum.ContextActionResult.Sink
    end,
    false,
    Enum.ContextActionPriority.High.Value,
    unpack(Enum.PlayerActions:GetEnumItems())
)

ContextActionService:BindActionAtPriority("Forward", dizzyForward, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.W, Enum.KeyCode.Up)
ContextActionService:BindActionAtPriority("Backward", dizzyBackward, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.S, Enum.KeyCode.Down)
ContextActionService:BindActionAtPriority("StrafeLeft", dizzyLeft, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.A, Enum.KeyCode.Left)
ContextActionService:BindActionAtPriority("StrafeRight", dizzyRight, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.D, Enum.KeyCode.Right)

local function stop()
	print("enabling controls again")
	ContextActionService:UnbindAction(FROZEN_ACTION_KEY)
end

ContextActionService:BindActionAtPriority("end", stop, false, Enum.ContextActionPriority.High.Value, Enum.KeyCode.Y)

Hopefully, this helps!

3 Likes

I have considered just making an animation that makes the player look dizzy but I would like to try with actually changing the movement script first before taking a shortcut.

Awesome, at least with the movement I can get started. Appreciate it!

1 Like

Here’s a cleaned up version that also lets you move diagonally.

local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")

local humanoid = Players.LocalPlayer.Character.Humanoid
local direction = Vector3.new(0,0,0)

local function changeDirection(inputState, newDirection)
	if inputState == Enum.UserInputState.Begin then
		direction = direction + newDirection
	elseif inputState == Enum.UserInputState.End then
		direction = direction - newDirection
	end
end

local function dizzyMovement(actionName, inputState, inputObject)
	if actionName == "Forward" then
		changeDirection(inputState, Vector3.new(0,0,-1))
	elseif actionName == "Backward" then
		changeDirection(inputState, Vector3.new(0,0,1))
	elseif actionName == "StrafeLeft" then
		changeDirection(inputState, Vector3.new(-1,0,0))
	elseif actionName == "StrafeRight" then
		changeDirection(inputState, Vector3.new(1,0,0))
	else
		warn("Bad actionName")
	end
end

local MovementBindings = {
	Forward = {Enum.KeyCode.W, Enum.KeyCode.Up},
	Backward = {Enum.KeyCode.S, Enum.KeyCode.Down},
	StrafeLeft = {Enum.KeyCode.A, Enum.KeyCode.Left},
	StrafeRight = {Enum.KeyCode.D, Enum.KeyCode.Right}
}

for bindingEvent, bindings in pairs(MovementBindings) do
	ContextActionService:BindAction(bindingEvent, dizzyMovement, false, unpack(bindings))
end

RunService.RenderStepped:Connect(function()
	humanoid:Move(direction, false)
end)

Thanks again for the help!

2 Likes

Looks awesome! Glad I was of service.

1 Like

I wouldn’t consider it a shortcut. It’s the more efficient way. Generally, it’s better to avoid actually changing the character movement as it can add a lot of complexity, and in a larger game it could cause problems in the long term. From what I’ve seen, it is better practice to move the character only for simple movements like walking forward, backwards, side to side and jump movement. Also manually moving it gives you less creative control and flexibility in the long term. Animating is definitely not a shortcut. Animations still move your character, it just uses a priority system that will keep your game clean and efficient.

I agree, there is no point in adding complexity when it could just create problems in the future, but in my case I am recreating a game, inspired from another that affects the controls in this way.