Posted: 27th Sep 2021 3:35
I am using this code here from a example, it works on its own but not with my game.

I am trying to ray cast the same group but nothing happens.

Here is the code I am trying to use.

+ Code Snippet
x1 = 0	:	y = 116	:	x2 = 600
ThisGroup = 4

    SetSpriteGroup(Player,xe)
    SetSpriteGroup(EnemyIdle,xe)
    
    If GetVirtualButtonPressed(1) 
		If ThisGroup > 0  
			If SpriteRayCastGroup(xe,x1,y,x2,y) = 1
				x2 = GetRayCastX() 
				DrawLine(x1,y,x2,y,MakeColor(255,0,0), MakeColor(255,0,0))
				
				DeleteSprite( GetRayCastSpriteID( ))
				DEC ThisGroup
			Endif
		Else
			//AddSprites()
			ThisGroup = 4
			x2 = 600
		Endif
	Endif
	
    Print( ThisGroup)


Posted: 27th Sep 2021 6:43
Can you post more of your code? Is your ray the proper coordinates you want? Looks like you could delete the player. I also can't see any purpose for decrementing ThisGroup based on that code snippet.
Posted: 27th Sep 2021 9:05
Im using this example

+ Code Snippet
// set window properties
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( 30, 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

AddSprites()

x1 = 0	:	y = 116	:	x2 = 600
ThisGroup = 4

do
    If GetRawKeyPressed(32) `[SPACE] 
		If ThisGroup > 0  
			If SpriteRayCastGroup(ThisGroup,x1,y,x2,y) = 1
				x2 = GetRayCastX() 
				DrawLine(x1,y,x2,y,MakeColor(255,0,0), MakeColor(255,0,0))
				DeleteSprite( GetRayCastSpriteID( ))
				DEC ThisGroup
			Endif
		Else
			AddSprites()
			ThisGroup = 4
			x2 = 600
		Endif
	Endif
	
    Print( ThisGroup)
    Sync()
loop

Function AddSprites()
	For x = 1 to 4
		This = CreateSprite(0)	:	SetSpriteSize(This,32,32)	:	SetSpritePosition(This,x*100,100)	:	SetSpriteGroup(This,x)	:	SetSpriteShape(This,2)	
	next x
EndFunction



My Player and enemy are in the same group, I'm not sure if that matters

But I am just using trigger box for the collision, looks like it works ok

The code I showed above is the whole thing related to what I need.

Thanks for your time

I do need one more thing if you can?

How do you check a impulse to slow down the movement of a sprite with SetSpritePhysicsImpulse?

SetSpritePhysicsImpulse( player, GetSpriteXByOffset(player), GetSpriteYByOffset(player), GetVirtualButtonState(2)/0.10, 0.0 )
Posted: 27th Sep 2021 13:27
Looks like your ray is cast from a local static position, it should be cast from player position +

I do need one more thing if you can?


I use this for a top down
+ Code Snippet
		vx#=GetSpritePhysicsVelocityX(gPlayer.sprite_id)
		vy#=GetSpritePhysicsVelocityY(gPlayer.sprite_id)
		Speed# = Sqrt( Abs(vy#) + Abs(vx#) )


but platformer you might want to take a different approach and just check the x velocity, y is your jump so as long as gravity is applied your y velocity should be capped

+ Code Snippet
if vy# > max_speed# : vy# = max_speed : endif
Posted: 28th Sep 2021 1:56
PartTimeCoder

Thanks for your help.

I have just one more problem

I am rotating a coin sprite but its not rotating around, its rotating in a spin.

SetSpriteAngle( allcoins, GetSpriteAngle( allcoins )-90 + (GetFrameTime()*500))
Posted: 28th Sep 2021 11:06
You mean its rotating from the 0,0 xy??

Use SetSpriteOffset, set the centre of the coin as the offset (spritewidth/2, spriteheight/2). now it should rotate around its centre