are you just aiming for the center? consider shooting at the "head" if the player is below then enemy, "feet" otherwise? then, pick a "side" based of above/below? i think you'll need to add this bit of "realism" re: LOS.
that wasn't sound advice... so, i tried shooting at both:
// set window properties
SetWindowTitle( "SpriteCast2" )
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
SetPhysicsGravity(0,0)
Enemy = CreateSprite(0) : SetSpriteSize(Enemy,32,64) : SetSpriteColor(Enemy,128,0,0,255) : SetSpritePositionByOffset(Enemy, 100,360)
Global Player as Integer
Player = CloneSprite(Enemy) : SetSpriteColor(Player,0,128,0,255) : SetSpritePositionByOffset(Player,980,360)
SetSpritePhysicsOn(Player,2) : SetSpritePhysicsDamping(Player,1) : SetSpritePhysicsCanRotate(Player,0)
For x = 0 to 3
This = CreateSprite(0) : SetSpriteSize(This,32,64) : SetSpritePositionByOffset(This,540,64 + 192*x)
SetSpritePhysicsOn(This,1)
Next x
Black = MakeColor(0,0,0)
Red = MakeColor(255,0,0)
do
UD# = GetJoystickY() : If UD# <> 0.0 then UD# = UD#/ABS(UD#)*100.0
LR# = GetJoystickX() : If LR# <> 0.0 then LR# = LR#/ABS(LR#)*100.0
SetSpritePhysicsVelocity(Player,LR#,UD#)
X# = GetSpriteXByOffset(Player) : Y# = GetSpriteYByOffset(Player)
Ray = SpriteRayCast(100.0,360.0,X#,Y#-32.0)
If Ray = 1
DrawLine(100,360,GetRayCastX(),GetRayCastY(),Black,Red)
if GetRayCastSpriteID() = Player then Print("HeadShot")
Endif
Ray = SpriteRayCast(100.0,360.0,X#,Y#+32.0)
If Ray = 1
DrawLine(100,360,GetRayCastX(),GetRayCastY(),Black,Red)
if GetRayCastSpriteID() = Player then Print("SweepTheLeg!")
Endif
Print( ScreenFPS() )
Sync()
loop
...and, something's wrong there, too. i think the rays are hitting each other?
i might be a coach, but we'll need a general manager for this one