Hello, I'm sure this has been asked before, but I couldn't find anything specific... I'm working on a platform game which is coming along nicely... However, I only want my character to be able to jump when in contact with the ground tiles...
Initially, I achieved this using a RayCast under his feet to check for contact. Like this:
RCCenterDown = PhysicsRayCast(GetSpriteXByOffset(Sprite), GetSpriteYByOffset(Sprite), GetSpriteXByOffset(Sprite), GetSpriteYByOffset(Sprite) + 25)
if GetRawKeyPressed(32) = 1 AND RCCenterDown = 1
// Jump
endif
The problem with this was that this checked for contact against everything and not just the ground so the 'Sprite' could jump off enemies etc...
I then tried to adapt this and check the RayCast SpriteID to check its a ground tile first (Group 1):
RCCenterDownSpriteID = GetRayCastSpriteID()
CanJump = 0
for i=1 TO 5000
if GetSpriteGroup(GroundTile[i]) = 1
if RCCenterDownSpriteID = GroundTile[i]
CanJump = 1
endif
endif
next i
This however, is very CPU intensive. If checks every tile every loop which drops my FPS...
Is there a better/alternative way to do this? Many thanks in advance!