Sliding speed is affected by the camera looking up or down

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to make a slide script based on LinearVelocity. I want to maintain the same slide velocity independently of the direction I’m looking at on the y axis.

  2. What is the issue? Whenever I slide, the slide velocity is affected by the camera’s cframe. However, when I look up or down the velocity of the slide is reduced due to the x and z angular coordinates being lowered.

  3. What solutions have you tried so far? I thought about multiplying the force by the y coordinate but it wasn’t as simple as I thought.

The code is down here.

local function slide()
	if debounce == false then
		canLoseSpeed = false
		local walkspeed = humanoid.WalkSpeed
		local slideForce = Instance.new("LinearVelocity", hrp)
		slideForce.Attachment0 = att0
		slideForce.MaxForce = math.huge
		
		local x,y,z = camera.CFrame:ToOrientation()
		local slideVector = CFrame.fromOrientation(x,y,z)

		slideForce.VectorVelocity = Vector3.new(slideVector.LookVector.X,0,slideVector.LookVector.Z) * walkspeed * 1.4
		
		local slidegoal = {}
		slidegoal.VectorVelocity = slideForce.VectorVelocity * 0.5
		local slidetween = TweenInfo.new(1,Enum.EasingStyle.Exponential,Enum.EasingDirection.In)
		local slidingtween = tweenService:Create(slideForce,slidetween,slidegoal)
		slidingtween:Play()

		debounce = true
		wait(1.4)
		slideForce:Destroy()
		canLoseSpeed = true
		debounce = false
	end
end

Thanks for all the help

You can try combining both HumanoidRootPart and Camera orientation angle

local forceUnit = 100
local _,CameraYAxis = workspace.CurrentCamera.CFrame:ToEulerAnglesYXZ()
local X = HumanoidRootPart.CFrame:ToEulerAnglesYXZ()
local slideForce = CFrame.Angles(X,CameraYAxis,0).lookVector*forceUnit

This code should give slide force at Camera’s horizontal rotation and HumanoidRootPart vertical rotation

1 Like

I would recommend re constructing a non pitched version of the cam cf.

local camCF = workspace.CurrentCamera.CFrame
local noPitchCF = CFrame.fromMatrix(camCF.Position, camCF.RightVector, Vector3.yAxis)

linearVelocity.VectorVelocity = noPitchCF.LookVector * slidingSpeed

just replace sliding speed with whatever speed you want the player to slide with

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.