Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
A jam submission

RagdollView game page

A basic verlet integration ragdoll
Submitted by Troypicol (@troypicol) — 1 day, 5 hours before the deadline
Add to collection

Play game

Ragdoll's itch.io page

Compressed Bytes used
730

Source Code (OPTIONAL)
function f(n)local c,t,a,l,r=unpack(n)local o,d=i[c],i[t]local n={o[1]-d[1],o[2]-d[2]}local f=sqrt(n[1]^2+n[2]^2)local e=(f-a)/f if(r==2and f>=a)return
local f=1-l i[c]={o[1]-n[1]*l*e,o[2]-n[2]*l*e}i[t]={d[1]+n[1]*f*e,d[2]+n[2]*f*e}end function c()for n=1,10do for n=1,#i do i[n]={mid(0,i[n][1],127),mid(0,i[n][2],127)}end for n in all(a)do f(n)end end end function n(n,o,d)line(i[n][1],i[n][2],i[o][1],i[o][2],d)end function o(n)local n=split(n,"|")for o in pairs(n)do n[o]=split(n[o])end return n end a=o"1,2,4,0.7|1,3,8,1,2|2,3,8,0.6|2,4,6,0.2|2,5,6,0.2|3,6,8,0.3|3,7,8,0.3|3,9,8,0.3,2|3,8,8,0.3,2|2,7,8,0.1,2|2,6,8,0.1,2|7,6,2,0.5,2|6,8,8,0.25|7,9,8,0.25|4,10,6,0.2|5,11,6,0.2"i=o("64,117|"..64-rnd(3)..","..119-rnd().."|"..64-rnd()..","..122-rnd().."|63,122|63,124|63,123|66,123|63,127|66,127|63,123|66,123")l=o"64,117|64,119|64,123|63,123|66,123|63,126|66,127|63,123|66,123|63,127|66,127|63,123|66,123"r={}t=.01function _update60()for o=1,#i do local n,d,e=i[o],l[o],{0,5}if(n[2]>=127)e={(d[1]-n[1])*.5/t,(d[2]-n[2])*.5/t}
l[o],i[o]=n,{n[1]+n[1]-d[1]+e[1]*t,n[2]+n[2]-d[2]+e[2]*t}end c()if(btnp(❎))for n=1,#i do i[n]={i[n][1]+(rnd(6)-3),i[n][2]-2-rnd(2)}end
if(btnp(🅾️))t=.01-t
cls(5)d="❎ to apply force!"e="🅾️ to toggle gravity: "..(t>0and"on"or"off")?d,4,5,0
?d,4,4,6
?e,4,13,0
?e,4,12,6
n(2,4,3)n(10,4,3)circfill(i[1][1],i[1][2],2,15)n(2,3,8)n(7,3,1)n(7,9,1)n(6,3,12)n(6,8,12)n(2,5,11)n(11,5,11)end

Leave a comment

Log in with itch.io to leave a comment.

Comments

Submitted

Very neat.  Crazy how well it works for so little code.  Is the array a randomized position for each joint when moving?

Developer (1 edit)

Thanks! There are basically two position arrays for each point, a current position and an old/previous position. The integration uses these when calculating new position each frame.

I initialise them with a few random offsets in one array so that the difference sets off the motion. (If they are the same then there is no motion outside of the force applied, in this case gravity.)

There is also an array of constraints which specifies either exact or minimum distances between points.

HostSubmitted

Ha, it's probably wrong to be having this much fun throwing a pixel body around! 😈
Reminds me of when Half Life 2 first came out and doing the same with CP guards and exploding barrels 💥
I've always been impressed by such physics demos, but blissfully unaware of how they work - black magic for sure! 😉
Great to see it replicated here in such a clean sandbox.
Thanks for the cool entry 👍

Developer (1 edit)

Just based on a little ragdoll implementation I was working on the other day. Thought it might make a nice little demo in the pico1k jam!

It isn’t especially minimized or optimized. I stuck it through shrink-8 to rename some variables and minimize whitespace.