Sorry for the bad title wasn’t sure what to put for it.
-
What do you want to achieve? Keep it simple and clear!
When the player reaches the edge of the screen prevent them from walking further back -
What is the issue? Include screenshots / videos if possible!
I’m guessing because of the way I have my code setup if you were to hold A and D (backward and forward buttons) at the same time it like bypasses the distance check letting the player walk further back.
-
What solutions have you tried so far?
I haven’t really tried much because I’m now sure what to do
Heres the code
--> this code is in a renderstep
local Vector,IsOnScreen = workspace.CurrentCamera:WorldToScreenPoint(Opponent.HurtBox.Position)
local Vector = Vector2.new(math.clamp(Vector.X, 0, workspace.CurrentCamera.ViewportSize.X), 0)
local DistanceFromLeft = (Vector - Vector2.new(0,0)).Magnitude
local DistanceFromRight = (Vector - Vector2.new(workspace.CurrentCamera.ViewportSize.X,0)).Magnitude
if math.floor(DistanceFromLeft) <= 190 or math.floor(DistanceFromRight) <= 190 then
if Modules.CharacterControl.Stuck == false then
Modules.CharacterControl.Stuck = true
Modules.CharacterControl:FreezeMovement("WalkSpeed") --> sets walkspeed to 0 so they cant walk further back
end
else
if Modules.CharacterControl.Stuck == true then
Modules.CharacterControl.Stuck = false
end
end
--> this code runs when they press D and if they're stuck
if Modules.CharacterControl.Stuck then
Modules.CharacterControl:UnfreezeMovement()
end