I tried using raycast instead of spherecast, it works perfectly now. I used 2 rays so the bullet has 'volume' to it.
This is the old
spherecast version:
///////////////////////////////////////////////////////////////////////
InitializeShotVars:
#Constant ShotSpeed# = 0.375
#Constant ShotSizeV# = 0.1875 // Half, from center
#Constant ShotSizeH# = 0.21875 // Half
RETURN
///////////////////////////////////////////////////////////////////////
UpdateShot:
FOR s = 1 TO ShotLimit
IF Shot[s] > 0
MoveObjectLocalX(Shot[s],ShotSpeed#*ShotDirection[s])
IF ShotDirection[s] = -1 // LEFT
ShotCollide0 = ObjectSphereCast(0, (GetObjectX(Shot[s])+ShotSizeH#),GetObjectY(Shot[s]),GameZ, (GetObjectX(Shot[s])-ShotSizeH#),GetObjectY(Shot[s]),GameZ, ShotSizeV#)
ShotCollide0ID = GetObjectRayCastHitID(0)
ShotCollide0X = GetObjectRayCastX(0)
ELSEIF ShotDirection[s] = 1 // RIGHT
ShotCollide0 = ObjectSphereCast(0, (GetObjectX(Shot[s])-ShotSizeH#),GetObjectY(Shot[s]),GameZ, (GetObjectX(Shot[s])+ShotSizeH#),GetObjectY(Shot[s]),GameZ, ShotSizeV#)
ShotCollide0ID = GetObjectRayCastHitID(0)
ShotCollide0X = GetObjectRayCastX(0)
ENDIF
IF ShotCollide0
GOSUB EnemyHitCheck
CreateParticle("explosion_sphere",ShotCollide0X,GetObjectY(Shot[s]),GameZ-0.5,1,0.07)
GOSUB DestroyShot
ENDIF
// Destroy if OffScreen
IF GetObjectX(Shot[s]) < GetCameraX(1)-13 OR GetObjectX(Shot[s]) > GetCameraX(1)+13 OR GetObjectY(Shot[s]) < GetCameraY(1)-9 OR GetObjectY(Shot[s]) > GetCameraY(1)+9
GOSUB DestroyShot
ENDIF
ENDIF
NEXT s
RETURN
///////////////////////////////////////////////////////////////////////
EnemyHitCheck:
FOR e = 1 TO EnemyTestLimit
IF ShotCollide0ID = EnemyTest[e]
GOSUB DamageEnemyTest
ENDIF
NEXT e
RETURN
Here is the new
raycast version:
///////////////////////////////////////////////////////////////////////
InitializeShotVars:
#Constant ShotSpeed# = 0.375
#Constant ShotSizeV# = 0.1875 // Half, from center
#Constant ShotSizeH# = 0.21875 // Half
RETURN
///////////////////////////////////////////////////////////////////////
UpdateShot:
FOR s = 1 TO ShotLimit
IF Shot[s] > 0
MoveObjectLocalX(Shot[s],ShotSpeed#*ShotDirection[s])
IF ShotDirection[s] = -1 // LEFT
ShotCollide1 = ObjectRayCast(0,(GetObjectX(Shot[s])+ShotSizeH#),(GetObjectY(Shot[s])+ShotSizeV#),GameZ, (GetObjectX(Shot[s])-ShotSizeH#),(GetObjectY(Shot[s])+ShotSizeV#),GameZ)
ShotCollide1ID = GetObjectRayCastHitID(0)
ShotCollide1X = Trunk(GetObjectRayCastX(0),2)
ShotCollide2 = ObjectRayCast(0,(GetObjectX(Shot[s])+ShotSizeH#),(GetObjectY(Shot[s])-ShotSizeV#),GameZ, (GetObjectX(Shot[s])-ShotSizeH#),(GetObjectY(Shot[s])-ShotSizeV#),GameZ)
ShotCollide2ID = GetObjectRayCastHitID(0)
ShotCollide2X = Trunk(GetObjectRayCastX(0),2)
ELSEIF ShotDirection[s] = 1 // RIGHT
ShotCollide1 = ObjectRayCast(0,(GetObjectX(Shot[s])-ShotSizeH#),(GetObjectY(Shot[s])+ShotSizeV#),GameZ, (GetObjectX(Shot[s])+ShotSizeH#),(GetObjectY(Shot[s])+ShotSizeV#),GameZ)
ShotCollide1ID = GetObjectRayCastHitID(0)
ShotCollide1X = Trunk(GetObjectRayCastX(0),2)
ShotCollide2 = ObjectRayCast(0,(GetObjectX(Shot[s])-ShotSizeH#),(GetObjectY(Shot[s])-ShotSizeV#),GameZ, (GetObjectX(Shot[s])+ShotSizeH#),(GetObjectY(Shot[s])-ShotSizeV#),GameZ)
ShotCollide2ID = GetObjectRayCastHitID(0)
ShotCollide2X = Trunk(GetObjectRayCastX(0),2)
ENDIF
IF ShotCollide1 OR ShotCollide2
GOSUB EnemyHitCheck
IF ShotCollide1
CreateParticle("explosion_sphere",ShotCollide1X,GetObjectY(Shot[s]),GameZ-0.5,1,0.07)
ELSEIF ShotCollide2
CreateParticle("explosion_sphere",ShotCollide2X,GetObjectY(Shot[s]),GameZ-0.5,1,0.07)
ENDIF
GOSUB DestroyShot
ENDIF
// Destroy if OffScreen
IF GetObjectX(Shot[s]) < GetCameraX(1)-13 OR GetObjectX(Shot[s]) > GetCameraX(1)+13 OR GetObjectY(Shot[s]) < GetCameraY(1)-9 OR GetObjectY(Shot[s]) > GetCameraY(1)+9
GOSUB DestroyShot
ENDIF
ENDIF
NEXT s
RETURN
///////////////////////////////////////////////////////////////////////
EnemyHitCheck:
FOR e = 1 TO EnemyTestLimit
IF ShotCollide1ID = EnemyTest[e] OR ShotCollide2ID = EnemyTest[e]
GOSUB DamageEnemyTest
ENDIF
NEXT e
RETURN