1st: i'm using Dynamic sprites, not Kinematic, for moveable stuff. see
HERE.
2nd: you haven't been very clear in many of your questions which requires others to guess at what you want. when your title includes Kinematic, some will assume "moving" vs "static" not strict kinematic because i'm not sure why you'd use true kinematic unless you're trying to mix standard sprite stuff with physics sprite stuff (which you have been and it's not recommended to mix multiple methods of moving sprites - for example, using SetSpritePosition on a Physics sprite breaks its physics for that loop cycle)),
3rd: you've revealed that you're using a move method that i'm not using in the example above (impulses); see # 2. it all matters.
4th: i won't re-write this. the notions are in there (crudely implemented) so you can adapt it however you want:
+ Code Snippet// Project: Jump
// Created: 2021-09-28
// By: Virtual Nomad
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Jump" )
SetWindowSize( 1280,720, 0 )
SetWindowAllowResize( 1 )
// set display properties
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 60, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
SetPhysicsScale(0.1)
Player = CreateSprite(0)
SetSpriteSize(Player,32,32)
SetSpritePositionByOffset(Player,200,600)
SetSpritePhysicsOn(Player,2)
SetSpritePhysicsCanRotate(Player,0)
Box = CreateSprite(0)
SetSpriteSize(Box,64,64)
SetSpritePositionByOffset(Box,500,600)
SetSpritePhysicsOn(Box,2)
SetSpritePhysicsCanRotate(Box,0)
SetSpriteColor(Box,255,0,0,255)
Plat1 = CreateSprite(0)
SetSpriteSize(Plat1, 300,32)
SetSpritePositionByOffset(Plat1,840,600)
SetSpritePhysicsOn(Plat1,1)
Plat2 = CreateSprite(0)
SetSpriteSize(Plat2, 300,32)
SetSpritePositionByOffset(Plat2,500,500)
SetSpritePhysicsOn(Plat2,2)
PJoint = CreatePrismaticJoint(Plat2, Plat1,0,0,1,0,0)
#Constant P2X# = GetSpriteXByOffset(Plat2)
PlatToggle = 1
Coin = CreateSprite(0)
SetSpriteSize(Coin,32,32)
SetSpritePositionByOffset(Coin,500,400)
SetSpriteShapeBox(Coin,-8,-8,8,8,0)
SetSpriteColor(Coin,255,255,0,255)
Score = 0
SetViewOffset(0,0) `just to break the walls
Ground = CreateSprite(0) : SetSpritePosition(Ground,0,720)
SetSpriteSize(Ground,1280, 32) : SetSpritePhysicsOn(Ground,1)
do
If GetRawKeyState(27) then Exit
If P2X# <= 400.0 and PlatToggle = -1 then PlatToggle = 1
If P2X# >= 600.0 and PlatToggle = 1 then PlatToggle = -1
SetSpritePhysicsVelocity(Plat2,PlatToggle*100.0,0)
PX# = GetSpriteXByOffset(Player) : PY# = GetSpriteYByOffset(Player)
Grounded = PhysicsRayCast( PX#,PY#,PX#,PY#+17)
If GetRawKeyState(ASC(" ")) and Grounded
Jump# = -150.0
Else
Jump# = GetSpritePhysicsVelocityY(Player)
Endif
If Grounded
ThisGround = GetRayCastSpriteID()
PMoveX# = GetSpritePhysicsVelocityX(ThisGround)
Else
PMoveX# = 0.0
EndiF
SetSpritePhysicsVelocity(Player,PMoveX# + (GetJoystickX()*50.0),Jump#)
If GetSpriteCollision(Player,Coin)
SetSpritePositionByOffset(Player,200,600)
SetSpritePhysicsVelocity(Player,0,0)
SetSpritePositionByOffset(Box,500,600)
INC Score
EndIf
Print("[A/D] = Move, [Space] = Jump")
Print("Score: "+STR(Score))
Print(ThisGround)
Sync()
loop