I’m working on a skiing system and for that I’m attaching the player to a sphere and then moving the sphere instead of the player. It works quite well except when I try to unequip the skiis, then the character just shoots up.
I’m attaching the character to the ball simply by setting its position to the ball’s position on frame rendered.
local function positionCharacter()
--check if the speed is almost 0
if ball.AssemblyLinearVelocity.Magnitude > 0.2 then
-- position the character to the ball and look in the direction the ball is moving
local rotation = (CFrame.lookAt(Vector3.new(prevPos.X,0,prevPos.Z), Vector3.new(ball.Position.X,0,ball.Position.Z))-Vector3.new(prevPos.X,0,prevPos.Z))
char:PivotTo(CFrame.new(ball.Position + CHARACTER_OFFSET) * rotation)
prevRotation = rotation
else
--position the character to the ball with previous rotation
char:PivotTo(CFrame.new(ball.Position + CHARACTER_OFFSET) * prevRotation)
end
prevPos = ball.Position
end
game["Run Service"]:BindToRenderStep("control", Enum.RenderPriority.Camera.Value-1, function()
local input = mainModule.getInput()
--set the velocity of the player based on player input and camera rotation
baseFriction.VectorVelocity = camera.CFrame:Inverse():VectorToObjectSpace(input * input.Magnitude * CHARACTER_SPEED)
--set the character position
positionCharacter()
--add friction
mainModule.applyFriction(ball, baseFriction, FRICTION_MULTIPLIER, FRICTION, directionalFriction, DIRCETIONAL_FRICTION, MAX_DIRECTIONAL_FRICTION)
--do certain actions if player is fast and when not
speedCheck()
speedAction()
end)
And while on screen it looks like it’s supposed to, in it’s properties it shows the character moving down.
Keep in mind that while the skiis are equipped the character is in a collision group where it can’t collide with anything. And when they are unequipped the collision group is set to the default.
I’ve tried just sending the current position of the player to the server in a loop, but that didn’t fix it.
I’m happy to receive any feedback!