I’m making a custom character controller for my game; and I’ve had an issue with it for a while: the player turns very slowly, it makes the player feel slippery and painful to control.
I remember a post I made a while back – I was still figuring how to make a controller – and someone suggested the idea to make a variable that controls the player’s turning speed, I’m wondering on how I would do that.
Here’s my code, any further questions are welcome!
local function moveToward(current, target, maxDelta)
local delta = target - current
local distance = delta.Magnitude
if distance <= maxDelta or distance == 0 then
return target
end
return current + delta.Unit * maxDelta
end
function player:MoveAndSlide()
local co = coroutine.create(function()
self:ChangeMoveDirection()
end)
coroutine.resume(co)
rs.RenderStepped:Connect(function(dt)
local acceleration = self.acceleration or 80
local deceleration = self.decceleration or 30
local velocity = self.hrp.AssemblyLinearVelocity
local currentVelocity = velocity
if self.grounded == false or self.state == 3 then
self.normal = Vector3.zero
self.air_Drag = 0
acceleration = self.air_Accel
deceleration = 20
velocity = Vector3.new(self.hrp.AssemblyLinearVelocity.X, 0, self.hrp.AssemblyLinearVelocity.Z)
currentVelocity = Vector3.new(velocity.X, self.hrp.AssemblyLinearVelocity.Y, velocity.Z)
else
self.air_Drag = 1
end
local maxSpeed = self.current_Speed
local moveDir = self.move_Direction
--moveDir = vect.projectOnPlane(moveDir, self.normal)
local targetVelocity = Vector3.zero
if moveDir.Magnitude > 0.001 then
targetVelocity = (moveDir.Unit * maxSpeed) * Vector3.new(1, self.air_Drag, 1)
if self.state == 1 then
self.state = 2
end
moveToward(currentVelocity, targetVelocity, acceleration * dt)
else
if self.state == 2 then
self.state = 1
end
currentVelocity = moveToward(currentVelocity, Vector3.new(0, self.hrp.AssemblyLinearVelocity.Y, 0), deceleration * dt)
end
if self.grounded == false or self.state == 3 then
currentVelocity = Vector3.new(
currentVelocity.X,
self.hrp.AssemblyLinearVelocity.Y,
currentVelocity.Z
)
end
self.hrp.AssemblyLinearVelocity = currentVelocity
end)
end
To get an idea on how bad the turning is, go into studio and set the baseplate’s friction to 0 and set its weight to 100. That’s how bad it is.
Any help would be appreciated! Thanks in advance!