yep, i edited the code to run 11 versions at once and now i see it is getting stuck, must have just been getting lucky before because it definitely didn't get stuck in like 30+ runs...
i did some more testing and it doesn't appear to be anything to do with the raycast, if you do a check a variable if the ray is false it still remains at the original value so it looks more like the box is just getting stuck on the corner of the ground or something rather than the velo not being applied.. this is especially noticeable as when you first run the app the player blocks appear to have a gap below them but as time goes on they get lower and lower
// Project: PlatTest
// Created: 2019-10-02
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Stuck2D" )
SetWindowSize( 1080, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1080, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetVSync(1)
SetPhysicsDebugOn()
blocks = 50 : width# = 1080.0/blocks
player as integer[11]
LR as integer[11]
onfloor as integer[11]
tempy = 60
for a = 1 to 11
for x = 0 to blocks-1
thisblock = CreateSprite(0)
SetSpriteSize(thisblock,width#,14.0)
SetSpritePosition(thisblock,x*width#,tempy)
SetSpritePhysicsOn(thisblock,1)
SetSpritePhysicsFriction(thisblock,0.0)
SetSpritePhysicsRestitution(thisblock,0.0)
SetSpriteVisible(thisblock,0)
next x
player[a] = CreateSprite(0)
SetSpriteSize(player[a],32,32)
SetSpriteColor(player[a],255,0,0,255)
SetSpritePosition(player[a],random2(50,656),tempy-35)
SetSpritePhysicsOn(player[a],2)
SetSpritePhysicsCanRotate(player[a],0)
SetSpritePhysicsFriction(player[a],0.0)
SetSpritePhysicsRestitution(player[a],0.0)
inc tempy, 60
LR[a] = 1
onfloor[a] = 1
next a
blue = MakeColor(0,0,255)
do
if GetRawMouseRightState() then StepPhysics(0)
if GetRawKeyState(27) = 1 then exit
for a = 1 to 11
px# = GetSpriteXByOffset(player[a]) : py# = GetSpriteYByOffset(player[a])
vx# = GetSpritePhysicsVelocityX(player[a]) : vy# = GetSpritePhysicsVelocityY(player[a])
If px# < GetSpriteWidth(player[a])*0.85 or GetSpriteXByOffset(player[a]) > 1080-(GetSpriteWidth(player[a])*0.85)
LR[a] = -LR[a]
endif
if PhysicsRayCast(px#-1,py#,px#+1,py#+20) = 1
//onfloor = 100
else
onfloor[a] = 0
endif
if onfloor[a] > 0
SetSpritePhysicsVelocity(player[a],LR[a]*512.0,0.0)
endif
DrawBox(px#-1,py#,px#+1,py#+20,blue,blue,blue,blue,1)
Print(str(a)+" : "+str(vx#,1)+" : "+str(LR[a])+" : "+str(onfloor[a]))
next a
Sync()
loop
with that in mind i found if you push back up against gravity it doesn't get stuck - i left this running for a good 10mins and not 1 got stuck
// Project: PlatTest
// Created: 2019-10-02
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Stuck2D" )
SetWindowSize( 1080, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1080, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetVSync(1)
SetPhysicsDebugOn()
blocks = 50 : width# = 1080.0/blocks
player as integer[11]
LR as integer[11]
onfloor as integer[11]
changed as integer[11]
tempy = 60
for a = 1 to 11
for x = 0 to blocks-1
thisblock = CreateSprite(0)
SetSpriteSize(thisblock,width#,14.0)
SetSpritePosition(thisblock,x*width#,tempy)
SetSpritePhysicsOn(thisblock,1)
SetSpritePhysicsFriction(thisblock,0.0)
SetSpritePhysicsRestitution(thisblock,0.0)
SetSpritePhysicsCanRotate(thisblock,0)
SetSpriteVisible(thisblock,0)
next x
player[a] = CreateSprite(0)
SetSpriteSize(player[a],32,32)
SetSpriteColor(player[a],255,0,0,255)
SetSpritePosition(player[a],random2(50,656),tempy-37)
SetSpritePhysicsOn(player[a],2)
SetSpritePhysicsCanRotate(player[a],0)
SetSpritePhysicsFriction(player[a],0.0)
SetSpritePhysicsRestitution(player[a],0.0)
//SetSpritePhysicsDamping(player[a],0.5)
inc tempy, 60
LR[a] = 1
onfloor[a] = 1
changed[a] = 0
next a
blue = MakeColor(0,0,255)
do
if GetRawMouseRightState() then StepPhysics(0)
if GetRawKeyState(27) = 1 then exit
for a = 1 to 11
px# = GetSpriteXByOffset(player[a]) : py# = GetSpriteYByOffset(player[a])
vx# = GetSpritePhysicsVelocityX(player[a]) : vy# = GetSpritePhysicsVelocityY(player[a])
If px# < GetSpriteWidth(player[a])*0.85 or GetSpriteXByOffset(player[a]) > 1080-(GetSpriteWidth(player[a])*0.85)
if changed[a] = 0
LR[a] = -LR[a]
changed[a] = 1
endif
else
changed[a] = 0
endif
if PhysicsRayCast(px#-1,py#,px#+1,py#+17) = 1
onfloor[a] = 1
else
onfloor[a] = 0
endif
if onfloor[a] > 0
SetSpritePhysicsVelocity(player[a],LR[a]*512.0,-0.9)
endif
DrawBox(px#-1,py#,px#+1,py#+20,blue,blue,blue,blue,1)
Print(str(a)+" : "+str(vx#,1)+" : "+str(LR[a])+" : "+str(onfloor[a])+" : "+str(vy#))
next a
Sync()
loop
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu