#Custom movement system, jittering when running into a wall.

3 messages · Page 1 of 1 (latest)

dry topaz
#

I'm making a custom movement system (the character is just a part) and I'm running into issues when colliding with a wall. I've tried running it on both RunService.Stepped and RunService.Heartbeat and it makes no difference. My main idea was to get any collisions and get the collision normal, then apply the opposite force to the player, but there seems to be no way to get the collision normal in Roblox. Any ideas?

RunService.Stepped:Connect(function(elapsed, delta)
    
    local inputAxis = Vector2.new(0, 0)
    if UserInputService:IsKeyDown(Enum.KeyCode.W) then inputAxis += Vector2.yAxis end
    if UserInputService:IsKeyDown(Enum.KeyCode.A) then inputAxis -= Vector2.xAxis end
    if UserInputService:IsKeyDown(Enum.KeyCode.S) then inputAxis -= Vector2.yAxis end
    if UserInputService:IsKeyDown(Enum.KeyCode.D) then inputAxis += Vector2.xAxis end
    if inputAxis.Magnitude ~= 0 then inputAxis = inputAxis.Unit end
    
    local direction = Vector3.new(inputAxis.Y, 0, inputAxis.X)
    direction = rotateVectorAround(direction, Vector3.yAxis, Camera.CFrame.Rotation.Y)
    
    movementVelocity = movementVelocity:Lerp(direction * speed, math.clamp(smoothing * delta, 0, 1))
    
    PlayerObject.AssemblyLinearVelocity = movementVelocity + velocity
    PlayerObject.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
    
end)
#

Initially I was using a cylinder part as the collider, but that one got stuck inside of the wall. Using a standard block prevents it from getting stuck, but it still jitters.

#

i made it a bit less prevalant by changing this

    movementVelocity = movementVelocity:Lerp(direction * speed, math.clamp(smoothing * delta, 0, 1))
    PlayerObject.AssemblyLinearVelocity = movementVelocity + velocity
```to this```lua
    PlayerObject.AssemblyLinearVelocity = PlayerObject.AssemblyLinearVelocity:Lerp(direction * speed, math.clamp(smoothing * delta, 0, 1))
```but that makes the character bounce and the problem still persists just at a way smaller scale