I was trying to use a physics force to build a jump system, so i find in agk commands list an example of it, and i trying to apply this into a different resolution but i can't make the jump work, can you guys help me? Thanks for your attention.
// Project: game
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "hexa" )
SetWindowSize( 1000, 750, 0 )
//SetWindowAllowResize( 1 ) // allow the user to resize the window
SetVirtualResolution(10,10)
SetPhysicsScale(0.5)
SetPhysicsGravity(0,500)
SetPhysicsDebugOn()
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 )
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
#constant groupground 1
#constant groupobject 2
#constant groupladder 3
#constant background 4
#constant player 5
LoadImage(2,"images/BG.png")
LoadImageResized(1,"images/robotfree/png/Idle (1).png",0.10,0.10,0)
LoadImage(3,"images\freetileset\png\Tiles\ground.png")
//background
createsprite(background,2)
FixSpriteToScreen(background,1)
//player
CreateSprite(player,1)
spr=player
SetSpriteShape(player,3)
SetSpritePosition(player,100,600)
setspritephysicson(player,2)
SetSpriteDepth(player,0)
SetSpritePhysicsCanRotate(player,0)
SetSpritePhysicsMass(player,100)
SetSpritePhysicsIsBullet(player,1)
SetSpritePhysicsFriction(player,0.1)
SetSpritePhysicsRestitution(player,0.25)
SetSpritePhysicsDamping(player,0.25)
MakeGround(3,0,700,0,0)
do
// Move Player to Left and Right
ix#=0.0
iy#=0.0
if GetRawKeyState(39) = 1
ix#=800.0
elseif GetRawKeyState(37) = 1
ix#=-800.0
endif
//Check was is below Feet
belowfeet=FeetAt(player,0,0.1 /*0.1**/ )
print("belowfeet:" + str(belowfeet))
print(ix#)
feet=FeetAt(spr,groupladder,-0.1)
print("feet:" + str(feet))
//Jump
if GetRawKeypressed(32) = 1
if AtGround(belowfeet)=1 then iy#= -800
endif
if 1=1
ladder=AtLadder(feet)
//print(ladder)
if ladder<>0 and abs(timer()-ladderdelay#)>1.0
if stayatladder=0
if getrawkeystate(38)=1 or getrawkeystate(40)=1 or GetSpritePhysicsVelocityY(spr)>1.0
stayatladder=1
joint=CreateMouseJoint( spr,getspritexbyoffset(spr), getspriteybyoffset(spr), 5000 )
SetJointMouseTarget(joint,getspritexbyoffset(feet), getspriteybyoffset(spr))
endif
endif
x#=getspritexbyoffset(feet)
y#=getspriteybyoffset(spr)
drawline(x#,0,x#,10, 255,255,0)
endif
//ladder mode
if stayatladder=1
if getrawkeystate(38)=1 and feet<>0 //Up
SetJointMouseTarget(joint,getspritexbyoffset(spr), getspriteybyoffset(spr)-0.25)
elseif getrawkeystate(40)=1 and feet<>0 //Down
SetJointMouseTarget(joint,getspritexbyoffset(spr), getspriteybyoffset(spr)+0.25)
elseif getrawkeypressed(39)=1 or getrawkeypressed(37)=1 or feet=0 //Links Rechts
if stayatladder=1
deletejoint(joint)
joint=0
stayatladder=0
ix#=ix# / 2.0
ladderdelay#=timer()
endif
else
endif
endif
endif
if ix#<>0.0 or iy#<>0.0 then setspritephysicsimpulse(spr,getspritexbyoffset(spr),getspriteybyoffset(spr),ix#,iy#)
//Print( ScreenFPS() )
Sync()
loop
function MakeGround(img,x#,y#,w#,h#)
//Ground
spr = CreateSprite(img)
//SetSpriteColor (spr,128,128,128,255)
//SetSpriteSize (spr,w#,h#)
SetSpritePosition(spr,x#,y#)
SetSpritePhysicsON(spr,1)
SetSpritePhysicsMass(spr,2)
SetSpritePhysicsCanRotate(spr,0)
SetSpritePhysicsFriction(spr,0.75)
SetSpritePhysicsRestitution(spr,0.5)
SetSpritePhysicsDamping(spr,0.5)
SetSpriteGroup( spr, groupground )
endfunction spr
function AtGround(spr)
ret=0
if spr=0 then exitfunction ret
group=getspritegroup(spr)
if group=groupobject or group=groupground
ret=1
endif
endfunction ret
function AtLadder(spr)
ret=0
if spr=0 then exitfunction ret
group=getspritegroup(spr)
if group=groupladder
ret=1
endif
endfunction ret
function MakeLadder(img,x#,y#,w#,h#)
//Ladder
spr = CreateSprite(img)
SetSpriteColor (spr,128,128,128,255)
SetSpriteSize (spr,w#,h#)
SetSpritePosition(spr,x#,y#)
SetSpritePhysicsON(spr,1)
setspritephysicsissensor(spr,1)
SetSpritePhysicsMass(spr,50)
SetSpritePhysicsCanRotate(spr,0)
SetSpritePhysicsFriction(spr,0.75)
SetSpritePhysicsRestitution(spr,0.5)
SetSpritePhysicsDamping(spr,0.5)
SetSpriteGroup( spr, groupladder )
endfunction spr
function MakeBox(img,x#,y#,w#,h#)
//Box
box = CreateSprite(img)
SetSpriteColor (box,233,75,80,255)
SetSpriteSize (box,w#,h#)
SetSpritePosition(box,x#,y#)
SetSpritePhysicsON(box,2)
SetSpritePhysicsMass (box,2)
SetSpritePhysicsCanRotate(box,1)
SetSpritePhysicsFriction(box,0.75)
SetSpritePhysicsRestitution(box,0.25)
SetSpritePhysicsDamping(box,0.5)
SetSpriteGroup( box, groupobject )
endfunction box
function FeetAt(spr,group,plusy#)
//feet position
x# = GetWorldXFromSprite(spr,0,GetSpriteHeight(spr)/2.0+plusy#)
y# = GetWorldYFromSprite(spr,0,GetSpriteHeight(spr)/2.0+plusy#)
DrawEllipse(x#,y#,.1,.1,MakeColor(255,255,0),MakeColor(255,0,0),1) //visible point for debug
if group //sprite filter by group
spr=GetSpriteHitGroup(group,x#,y#) //for not hit the player itself such at ladder
else
spr=GetSpriteHit(x#,y#)
endif
endfunction spr