You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I would like the character to stop bouncing off of walls which aren’t there. - What is the issue? Include screenshots / videos if possible!
- What solutions have you tried so far? Did you look for solutions on the Creator Hub?
I’ve specifically tried using dot products and the angle function by comparing the surface normal to a vector which only goes up and base whether the character should bounce off of that detail, but neither function has worked
local ContextActionService = game:GetService("ContextActionService")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local RemoteEvents = game.ReplicatedStorage.RemoteEvents
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local ClientSlideVelocity = Instance.new("LinearVelocity")
ClientSlideVelocity.Name = "MovementVelocity"
ClientSlideVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
ClientSlideVelocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
ClientSlideVelocity.ForceLimitsEnabled = true
ClientSlideVelocity.MaxAxesForce = Vector3.new(10000, 0, 10000)
ClientSlideVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
ClientSlideVelocity.Attachment0 = HumanoidRootPart.RootAttachment
ClientSlideVelocity.Enabled = false
ClientSlideVelocity.Parent = HumanoidRootPart
local RaycastParameters = RaycastParams.new()
RaycastParameters.RespectCanCollide = true
RaycastParameters.FilterDescendantsInstances = {Character}
local Magnitude = Instance.new("NumberValue")
local UnitVector = Instance.new("Vector3Value")
local SlidingAnimation = Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations.Slide)
local DivingAnimation = Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations.Dive)
local SlidingWithBombAnimation = Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations.SlideWithBomb)
local ParryAnimation = Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animations.Parry)
local TweenToZero = TweenService:Create(Magnitude, TweenInfo.new(0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Value = 0})
local TimeJumped = 0
local TimeAbilityStarted = 0
local MovementDebounce = false
Character:SetAttribute("IsUsingAbility", false)
Character:SetAttribute("LastMovementState", "None")
local PlaySound = game.ReplicatedStorage.RemoteEvents.PlaySound
local EndSound = game.ReplicatedStorage.RemoteEvents.EndSound
function StopMovement()
if Character:FindFirstChild("Timebomb") then
Humanoid.WalkSpeed = 24
else
Humanoid.WalkSpeed = 16
end
Humanoid.JumpPower = 50
Humanoid.HipHeight = 0
ClientSlideVelocity.Enabled = false
SlidingAnimation:Stop(0)
SlidingWithBombAnimation:Stop(0)
Magnitude.Value = 0
DivingAnimation:Stop(0)
ClientSlideVelocity.MaxAxesForce = Vector3.new(10000, 0, 10000)
Character:SetAttribute("IsUsingAbility", false)
EndSound:FireServer("Slide")
EndSound:FireServer("Dive")
end
function UpdateMagnitudeValue()
TweenToZero:Cancel()
Magnitude.Value = math.min(Magnitude.Value * 1.1, 55)
TweenToZero:Play()
end
function F(x)
return -3 - x
end
function Slide(Name, InputState, InputObject)
if InputState ~= Enum.UserInputState.Begin or Humanoid.FloorMaterial == Enum.Material.Air or MovementDebounce then return end
MovementDebounce = true
Character:SetAttribute("IsUsingAbility", true)
UnitVector.Value = Character:GetAttribute("AccurateMoveDirection").Magnitude ~= 0 and Character:GetAttribute("AccurateMoveDirection") or HumanoidRootPart.CFrame.LookVector
Magnitude.Value = 45
ClientSlideVelocity.Enabled = true
TweenToZero:Play()
TimeAbilityStarted = os.clock()
ParryAnimation:Stop(0)
if Character:FindFirstChild("Timebomb") then
ClientSlideVelocity.MaxAxesForce = Vector3.new(50000, 0, 50000)
end
if os.clock() - TimeJumped < 0.3 then
print("1")
Humanoid.HipHeight = -2
PlaySound:FireServer("Dive")
Character:SetAttribute("LastMovementState", "Diving")
DivingAnimation:Play(0)
else
print("2")
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 1
Humanoid.HipHeight = -1
PlaySound:FireServer("Slide")
Character:SetAttribute("LastMovementState", "Sliding")
if Character:FindFirstChild("Timebomb") then
SlidingWithBombAnimation:Play(0)
else
SlidingAnimation:Play(0)
end
end
RemoteEvents.EmitMovementParticles:FireServer(HumanoidRootPart.Position + Vector3.new(0, Humanoid.HipHeight, 0))
while Magnitude.Value > 0 do
task.wait()
end
StopMovement()
task.wait(1.6)
MovementDebounce = false
return Enum.ContextActionResult.Pass
end
function Parry(Name, InputState, InputObject)
if InputState ~= Enum.UserInputState.Begin or Character:GetAttribute("ParryOnCooldown") == true or Character:FindFirstChild("Timebomb") or Character:GetAttribute("IsUsingAbility") == true then return end
ParryAnimation:Play(0)
RemoteEvents.AttemptParryOnServer:FireServer()
PlaySound:FireServer("Punch")
end
Humanoid.StateChanged:Connect(function(Old, New)
if New == Enum.HumanoidStateType.Jumping then
TimeJumped = os.clock()
end
end)
UserInputService.JumpRequest:Connect(function()
if Character:GetAttribute("IsUsingAbility") == true and os.clock() - TimeAbilityStarted > 0.3 then
StopMovement()
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
if Character:GetAttribute("LastMovementState") == "Diving" then
HumanoidRootPart.AssemblyLinearVelocity += Humanoid.MoveDirection * 20
end
end
end)
Magnitude.Changed:Connect(function()
ClientSlideVelocity.VectorVelocity = UnitVector.Value * Magnitude.Value
end)
UnitVector.Changed:Connect(function()
ClientSlideVelocity.VectorVelocity = UnitVector.Value * Magnitude.Value
end)
ContextActionService:BindAction("Slide", Slide, true, Enum.KeyCode.E)
ContextActionService:BindAction("Parry", Parry, true, Enum.KeyCode.C)
RunService.Stepped:Connect(function()
if Character:GetAttribute("IsUsingAbility") == false or ClientSlideVelocity.VectorVelocity.Magnitude <= 0 then return end
if os.clock() - TimeAbilityStarted > 3 then StopMovement() return end
local Raycast = workspace:Blockcast(CFrame.new(HumanoidRootPart.Position + Vector3.new(0, F(Humanoid.HipHeight), 0) - HumanoidRootPart.CFrame.LookVector), Vector3.new(2, 1, 2), ClientSlideVelocity.VectorVelocity.Unit * 5, RaycastParameters)
local GroundRaycast = workspace:Raycast(HumanoidRootPart.Position, Vector3.new(0, -5, 0), RaycastParameters)
if GroundRaycast then
print(GroundRaycast.Normal)
end
if not Raycast then return end
if (Raycast.Instance.Parent:FindFirstChild("Humanoid") and Character:FindFirstChild("Timebomb")) then
StopMovement()
elseif math.deg(Raycast.Normal.Unit:Angle(Vector3.new(0, 1, 0))) >= 90 then
print(math.deg(Raycast.Normal:Angle(Vector3.new(0, 1, 0))))
print(Raycast.Normal.Unit)
UnitVector.Value = (UnitVector.Value - 2 * UnitVector.Value:Dot(Raycast.Normal.Unit) * Raycast.Normal).Unit
UpdateMagnitudeValue()
end
end)