Log In  


Cart #jegurokug-1 | 2022-10-22 | Code ▽ | Embed ▽ | No License

Hello, im wondering why the velocity and acceleration (vx and va) dont go to zero when you go left then let go.
Also note that the maximums are different.

Controls:
Left -- go left
Right -- go right
X -- force vx and va values to zero

is this just a quirk with pico-8?

Thanks :)

Code:

function _init()
x=0
vx=0
ax=0
end

function _update60()
	if btn(➡️) then
		ax+=.01
	end
	if btn(⬅️) then
		ax-=.01
	end
	if btn(❎) then
		ax=0
		vx=0
	end

	vx+=ax
	x+=vx

	vx*=.9
	ax*=.9
end

function _draw()
	cls()
	line(x,0,x,127,7)

	print(vx.." velocity",0,0,2)
	print(ax.." acceleration")
	print(x.." x")

end



Hi @Thiskul.

It is indeed a quirk in Pico-8. While the output shows the lowest number as 0.0001 it actually goes smaller than this and causes problems.

The best solution I have found is to add these two lines after your ax*=.9

	if (abs(vx)<.0002) vx=0
	if (abs(ax)<.0002) ax=0

I had to do this in a test platformer I was working on. By checking for that small value, that will fix the "floating" movement.


@dw817 hi! first of all, thank you.
second of all, it worked!
third of all, i actually am using this for a platformer, quite the coincidence!
fourth of all, round of applause to you for being so active in the community, i cant look in 2 blog posts without seeing you :).

TLDR: Thank you! :)


Hi @Thiskul. You are very welcome ... and yeah at times I really need to be working on my own Pico-8 code instead of commenting on everything.

Nonetheless I do try to help and encourage others when I can. :)

Glad those 2-lines of code helped you.

You can help the community as well. If you see a comment that is not about Pico-8, usually in a really foreign language, not at all English letters, you can click the triangle to the right of it and select it as SPAM.

One of our active moderators will see this and remove the entire message.

Thanks !



[Please log in to post a comment]