Hi guys,
I'm writing a simple ragdoll from scratch, but there's two thing acting weird that I'm unsure of.
1 - The joint limits I'm setting seem to have no effect, and;
2 - When in physics debug mode, all moving sprites have a line drawn from the sprite to the top left of the play area.
What's happening;
Once the "ragdoll" comes in contact with the floor, instead of just slumping over it rather explodes and the sprites go nuts all over the play area.
Check out the code below,
no external images/resources (I lied, it does use one png, one pixel by one pixel, white, I'll link it below), so just paste/run.
Note: When running my code, be sure to close the player a few seconds after things go crazy, as it looks like it's starting a hefty memory leak when things go awry.
pxl.png (download resource image)
// Project: MEario
// Created: 2016-10-13
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "MEario" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
setPhysicsScale(0.15)
setPhysicsGravity(4,10)
setPhysicsDebugOn()
loadimage(1,"pxl.png")
function BRICK(x,y)
i = CreateSprite(1)
setspritex(i,x)
setspritey(i,y)
setspritecolor(i,255,255,255,255)
setspritesize(i,5,5)
setspritephysicson(i,1)
endfunction
function SPAWNME(x,y)
h = createsprite(1)
n = createsprite(1)
ls = createsprite(1)
rs = createsprite(1)
le = createsprite(1)
re = createsprite(1)
lh = createsprite(1)
rh = createsprite(1)
w = createsprite(1)
lk = createsprite(1)
rk = createsprite(1)
lf = createsprite(1)
rf = createsprite(1)
setspritesize(h,5,5)
setspritesize(n,5,5)
setspritesize(ls,5,5)
setspritesize(rs,5,5)
setspritesize(le,5,5)
setspritesize(re,5,5)
setspritesize(lh,5,5)
setspritesize(rh,5,5)
setspritesize(w,5,5)
setspritesize(lk,5,5)
setspritesize(rk,5,5)
setspritesize(lf,5,5)
setspritesize(rf,5,5)
setspritephysicson(h,2)
setspritephysicson(n,2)
setspritephysicson(ls,2)
setspritephysicson(rs,2)
setspritephysicson(le,2)
setspritephysicson(re,2)
setspritephysicson(lh,2)
setspritephysicson(rh,2)
setspritephysicson(w,2)
setspritephysicson(lk,2)
setspritephysicson(rk,2)
setspritephysicson(lf,2)
setspritephysicson(rf,2)
setSpritePhysicsRestitution( h, 0.0 )
setSpritePhysicsRestitution( n, 0.0 )
setSpritePhysicsRestitution( ls, 0.0 )
setSpritePhysicsRestitution( rs, 0.0 )
setSpritePhysicsRestitution( le, 0.0 )
setSpritePhysicsRestitution( re, 0.0 )
setSpritePhysicsRestitution( lh, 0.0 )
setSpritePhysicsRestitution( rh, 0.0 )
setSpritePhysicsRestitution( w, 0.0 )
setSpritePhysicsRestitution( lk, 0.0 )
setSpritePhysicsRestitution( rk, 0.0 )
setSpritePhysicsRestitution( lf, 0.0 )
setSpritePhysicsRestitution( rf, 0.0 )
//spawn head
setspritex(h,x)
setspritey(h,y)
//spawn neck
setspritex(n, getspritex(h))
setspritey(n, getspritey(h)+7)
//connect head to neck
j1 = CreateRevoluteJoint(h,n,2.5,2.5,1)
setjointlimiton(j1,-0.5,0.5)
//spawn shoulders
setspritex(ls, getspritex(n)-7)
setspritey(ls, getspritey(n))
setspritex(rs, getspritex(n)+7)
setspritey(rs, getspritey(n))
//connect shoulders to neck (rigid joints)
j2 = createweldjoint(ls,n,2.5,2.5,1)
j3 = createweldjoint(rs,n,2.5,2.5,1)
//setjointlimiton(j2,-0.5,0.5)
//setjointlimiton(j3,-0.5,0.5)
//spawn elbows
setspritex(le,getspritex(ls))
setspritey(le,getspritey(ls)+7)
setspritex(re,getspritex(rs))
setspritey(re,getspritey(rs)+7)
//connect elbows to shoulders
j4 = CreateRevoluteJoint(le,ls,2.5,2.5,1)
j5 = CreateRevoluteJoint(re,rs,2.5,2.5,1)
setjointlimiton(j4,-0.5,0.5)
setjointlimiton(j5,-0.5,0.5)
//spawn hands
setspritex(lh,getspritex(le))
setspritey(lh,getspritey(le)+7)
setspritex(rh,getspritex(re))
setspritey(rh,getspritey(re)+7)
//connect hands to elbows
j6 = CreateRevoluteJoint(le,lh,2.5,2.5,1)
j7 = CreateRevoluteJoint(re,rh,2.5,2.5,1)
setjointlimiton(j6,-0.5,0.5)
setjointlimiton(j7,-0.5,0.5)
//spawn waist
setspritex(w,getspritex(n))
setspritey(w,getspritey(n)+14)
//connect waist to neck
j8 = CreateRevoluteJoint(n,w,2.5,2.5,1)
setjointlimiton(j8,-14.5,14.5)
//spawn knees
setspritex(lk,getspritex(w)-7)
setspritey(lk,getspritey(w)+7)
setspritex(rk,getspritex(w)+7)
setspritey(rk,getspritey(w)+7)
//connect knees to waist
j9 = CreateRevoluteJoint(lk,w,2.5,2.5,1)
j10 = CreateRevoluteJoint(rk,w,2.5,2.5,1)
setjointlimiton(j9,-0.5,0.5)
setjointlimiton(j10,-0.5,0.5)
//spawn feet
setspritex(lf,getspritex(lk))
setspritey(lf,getspritey(lk)+7)
setspritex(rf,getspritex(rk))
setspritey(rf,getspritey(rk)+7)
//connect feet to knees
j11 = CreateRevoluteJoint(lf,lk,2.5,2.5,1)
j12 = CreateRevoluteJoint(rf,rk,2.5,2.5,1)
setjointlimiton(j11,-0.5,0.5)
setjointlimiton(j12,-0.5,0.5)
endfunction
//turn on gravity
//SetPhysicsDebugOn ( )
i = random(0,200)
ii = random(700,720)
spawnme(i,ii)
brick(0,763)
brick(5,763)
brick(10,763)
brick(15,763)
brick(20,763)
brick(25,763)
brick(30,763)
brick(35,763)
brick(40,763)
brick(45,763)
brick(50,763)
brick(55,763)
brick(60,763)
brick(65,763)
brick(70,763)
brick(75,763)
brick(80,763)
brick(85,763)
brick(90,763)
brick(95,763)
brick(100,763)
brick(105,763)
brick(110,763)
brick(115,763)
brick(120,763)
brick(125,763)
brick(130,763)
brick(135,763)
brick(140,763)
brick(145,763)
brick(150,763)
brick(155,763)
brick(160,763)
brick(165,763)
brick(170,763)
brick(175,763)
brick(180,763)
brick(185,763)
brick(190,763)
brick(195,763)
brick(200,763)
brick(205,763)
brick(210,763)
brick(215,763)
do
//Print( ScreenFPS() )
Sync()
loop
-Writing programs for years, new to AGK2