this part is wrong.
u overwrite the physics.
normal the elevator falling down.
why not use this kinematic physic flag?
see example below.
if pause = 0
if moving = 1
SetSpritePosition(elevator,GetSpriteX(elevator),GetSpriteY(elevator)-2)
else if moving = 2
SetSpritePosition(elevator,GetSpriteX(elevator),GetSpriteY(elevator)+1)
else if moving = 3
SetSpritePosition(elevator,GetSpriteX(elevator),GetSpriteY(elevator)-2)
endif
endif
endif
else
SetSpritePosition(elevator,GetSpriteX(elevator),GetSpriteY(elevator))
endif
rem
rem AGK Application 108 19
rem MR
SetVirtualResolution(1280, 800)
SetPhysicsGravity(0, 1000)
global Ground_Spr
global Charater_Spr
global RaycastBottom
global dim RaycastRight[2]
global dim RaycastLeft[2]
global moving as Integer
global pause = 0
// Create Ground
Ground_Spr = CreateSprite(0)
SetSpriteSize(Ground_Spr, 900, 32)
SetSpritePosition(Ground_Spr, 0, 500)
SetSpritePhysicsOn(Ground_Spr, 1)
SetSpritePhysicsRestitution(Ground_Spr, 0)
SetSpriteGroup(Ground_Spr, 1)
// Create Character
Character_Spr = CreateSprite(0)
SetSpriteSize(Character_Spr, 32, 32)
SetSpriteColor(Character_Spr, 255, 0, 0, 255)
SetSpritePosition(Character_Spr, 32, 450)
SetSpritePhysicsOn(Character_Spr, 2)
SetSpritePhysicsCanRotate(Character_Spr, 0)
SetSpritePhysicsRestitution(Character_Spr, 0)
Slider = CreateSprite(0)
SetSpriteSize(slider,25,500)
SetSpritePosition(slider,1040,100)
elevator = CreateSprite(0)
SetSpriteColor(elevator,181,230,29,255)
SetSpriteSize(elevator,200,80)
SetSpritePosition(elevator,950,500)
SetSpriteDepth(elevator,0)
SetSpritePhysicsOn(elevator,3) // 1=static, 2=dynamic, 3=kinematic
SetSpritePhysicsCanRotate (elevator,0)
SetSpritePhysicsmass(elevator,10000)
weight = GetSpritePhysicsMass (elevator) * 1000
do
// Pause
if GetRawKeyPressed (13) = 1 // press Enter Key to pause game
if pause = 0
pause = 1
SetSpritePhysicsForce (elevator,GetSpriteX(elevator),GetSpriteY(elevator),0,-weight)
SetSpritePhysicsOff(Character_Spr)
//SetSpritePhysicsOff(elevator)
else
pause = 0
SetSpritePhysicsOn(Character_Spr,2)
//SetSpritePhysicsOn(elevator,2)
endif
endif
spry = GetSpriteY(elevator)
if spry > 150 and moving = 0 then moving = 1
if spry <= 150 and (moving = 1 or moving = 3) then moving = 2
if spry >= 500 and moving = 2 then moving = 3
if pause = 0
if moving = 1
SetSpritePosition(elevator,GetSpriteX(elevator),GetSpriteY(elevator)-2)
else if moving = 2
SetSpritePosition(elevator,GetSpriteX(elevator),GetSpriteY(elevator)+1)
else if moving = 3
SetSpritePosition(elevator,GetSpriteX(elevator),GetSpriteY(elevator)-2)
endif
endif
endif
else
//SetSpritePosition(elevator,GetSpriteX(elevator),GetSpriteY(elevator))
endif
// Raycast Bottom
RaycastBottom = PhysicsRayCastGroup(1, GetSpriteXByOffset(Character_Spr), GetSpriteYByOffset(Character_Spr), GetSpriteXByOffset(Character_Spr), GetSpriteYByOffset(Character_Spr) + 18)
// Raycast Right
RaycastRight[1] = PhysicsRayCastGroup(1, GetSpriteXByOffset(Character_Spr), GetSpriteY(Character_Spr), GetSpriteXByOffset(Character_Spr) + 18, GetSpriteY(Character_Spr))
RaycastRight[2] = PhysicsRayCastGroup(1, GetSpriteXByOffset(Character_Spr), GetSpriteY(Character_Spr) + 32, GetSpriteXByOffset(Character_Spr) + 18, GetSpriteY(Character_Spr) + 32)
// Raycast Left
RaycastLeft[1] = PhysicsRayCastGroup(1, GetSpriteXByOffset(Character_Spr), GetSpriteY(Character_Spr), GetSpriteXByOffset(Character_Spr) - 18, GetSpriteY(Character_Spr))
RaycastLeft[2] = PhysicsRayCastGroup(1, GetSpriteXByOffset(Character_Spr), GetSpriteY(Character_Spr) + 32, GetSpriteXByOffset(Character_Spr) - 18, GetSpriteY(Character_Spr) + 32)
// Character Movement
if pause = 0
if GetRawKeyState(37) = 1 AND RaycastLeft[1] = 0 AND RaycastLeft[2] = 0
SetSpritePhysicsVelocity(Character_Spr, -200, GetSpritePhysicsVelocityY(Character_Spr))
elseif GetRawKeyState(39) = 1 AND RaycastRight[1] = 0 AND RaycastRight[2] = 0
SetSpritePhysicsVelocity(Character_Spr, 200, GetSpritePhysicsVelocityY(Character_Spr))
else
SetSpritePhysicsVelocity(Character_Spr, 0, GetSpritePhysicsVelocityY(Character_Spr))
endif
if GetRawKeyPressed(32) = 1 AND RaycastBottom = 1
SetSpritePhysicsVelocity(Character_Spr, GetSpritePhysicsVelocityX(Character_Spr), -700)
endif
endif
Sync()
loop
AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)