(Advanced Scripting) - How do I recreate Paper io movement

  1. What do you want to achieve?
    I want to recreate Paper io movement. You can try the game in this link Paper.io play online (paper-io.com)

  2. What is the issue?
    The issues is that when I make a turn, is very brusque, I want it to be more circular and slower

  3. What solutions have you tried so far?
    I’ve tried to add a lerp but you can see in the video, at the end, that the turn is not fluid.

Here is the script I tried:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local maxSpeed = 20 -- adjust this to set the maximum speed of the player
local moveDirection = Vector3.new(0, 0, 0)

local function updateMoveDirection()
	local mousePos = mouse.Hit.p
	local playerPos = player.Character.HumanoidRootPart.Position
	local newMoveDirection = (mousePos - playerPos).unit

	moveDirection = moveDirection:Lerp(newMoveDirection, 0.02) -- adjust the 0.1 value to set the smoothness of the player's movement
end

game:GetService("RunService").Heartbeat:Connect(function()
	updateMoveDirection()

	player.Character.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position + moveDirection * maxSpeed)
end)

u gotta mess with the lerp argument 2 number a bit.

Okay so what happends here is Lerping is like adding a number with provided number’s 0.02 increased.
What you should do to prevent it rotating faster when the angle between your mouse’s position and player’s position is too much is you should set a constant time and lerp it according to that.

local lerp_constant = 1; -- lerp will be done within 1 second.

moveDirection = moveDirection:Lerp(newMoveDirection, lerp_constant / (newMoveDirection - moveDirection).Magnitude); -- moveDirection will be as same as newMoveDirection within 1 second always.

Hey im curious did you get it to work well?

I don’t think you understood his problem, he wants the turns to be more circular and slower, not quicker

After much testing, I have found that this is indeed correct and you have to use this to get the smooth, regular and circular rotating you want. In future you can use trial and error to find the optimal time yourself by simply changing it and testing it, but the value I found that was the most smooth and not too jittery was
local lerp_constant = 0.1

The constant should also be multiplied by Delta time or else different frame rates will experience different results.

yes I somehow managed to make it work perfectly

no worries guys it’s already done, but thanks anyways

If you are curious of how it’s working, I leave a video:

The Script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local maxSpeed = 20 -- adjust this to set the maximum speed of the player
local moveDirection = Vector3.new(1, 0, 0)

function rotateVectorAroundAxis(axis, vector, angle)
	local zVector = (vector:Cross(axis)) / axis.Magnitude
	return math.cos(angle) * vector + math.sin(angle) * zVector
end

local function updateMoveDirection()
	local mousePos = mouse.Hit.p
	local playerPos = player.Character.HumanoidRootPart.Position
	local newMoveDirection = (mousePos - playerPos).unit
	
	local lerp_constant = 0.01
	 
	local angNewMovedir = math.asin( (moveDirection:Cross(newMoveDirection)).Y )
	
	
	--print(angNewMovedir)
	local maxAngle = math.rad(6)
	
	--angNewMovedir = -angNewMovedir * 0.1 	
	if angNewMovedir > maxAngle then
		angNewMovedir = maxAngle
	elseif angNewMovedir < -maxAngle then
		angNewMovedir = -maxAngle
	end

	moveDirection = rotateVectorAroundAxis(Vector3.new(0,1,0), moveDirection, -angNewMovedir )
	moveDirection = moveDirection.Unit
end

game:GetService("RunService").Heartbeat:Connect(function()
	updateMoveDirection()

	player.Character.Humanoid:MoveTo(player.Character.HumanoidRootPart.Position + moveDirection * maxSpeed)
end)

Thanks for those who tried to help

3 Likes

Thats great. Also, just wondering how did you get such a smooth trail behind the block? I might need it for another project in future

and then i added a normal trail. There is an important thing: don’t set transparency more than 0, just set the color and the birghtness

Can you tell me what size settings you used? I’m trying to replicate yours

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