Freaky Line of Sight ¿Bug? in dungeon crawler

0 favourites
  • 7 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • I´m working on a checkered grid dungeon crawler, and while working with a Ranged unit, that should only attack while aligned with the player (think of it as a Ranged Rook) when I check LineOfSigth in the 90° it doesn´t detect it, it does work with every other angle thought, I tried trouble-shooting it by removing everything else but it still gives trouble with that angle, any ideas what I might be doing wrong?

    I´ll leave some caps:

    Subscribe to Construct videos now

    as you can see, all enemies attack expect the one straight down

    (angle of sigth is only used for LOS, and angle of movement marks the moving direction

    * On function 'EnemyRanged_PathFinding'

    * Parameter 'UID' (Number)

    + Enemy: Pick instance with UID UID

    // Check if the Enemy is closer to the Player in Y Axis

    ----+ System: abs(Enemy.X - Samurai.X) ≥ abs(Enemy.Y- Samurai.Y)

    --------+ System: Enemy.X < Samurai.X

    --------// Right

    ---------> Enemy: Set AngleOfSight to 0

    --------+ System: Enemy.X > Samurai.X

    --------// Left

    ---------> Enemy: Set AngleOfSight to 180

    --------+ System: Enemy.Y < Samurai.Y

    --------// Up

    ---------> Enemy: Set AngleOfMovement to 90

    --------+ System: Enemy.Y > Samurai.Y

    --------// Down

    ---------> Enemy: Set AngleOfMovement to 270

    // Check if the Enemy is closer to the Player in X Axis

    ----+ System: abs(Enemy.X - Samurai.X) < abs(Enemy.Y- Samurai.Y)

    --------+ System: Enemy.Y < Samurai.Y

    --------// Up

    ---------> Enemy: Set AngleOfSight to 90

    --------+ System: Enemy.Y > Samurai.Y

    --------// Down

    ---------> Enemy: Set AngleOfSight to 270

    --------+ System: Enemy.X < Samurai.X

    --------// Right

    ---------> Enemy: Set AngleOfMovement to 0

    --------+ System: Enemy.X > Samurai.X

    --------// Left

    ---------> Enemy: Set AngleOfMovement to 180

    ----+ (no conditions)

    -----> Functions: Call EnemyRanged_MoveOrAttack (UID: UID)

    --------

    * On function 'EnemyRanged_MoveOrAttack'

    * Parameter 'UID' (Number)

    + Enemy: Pick instance with UID UID

    // if the player is in range, attack

    ----+ Enemy: Has LineOfSight from (Self.X, Self.Y) angle Self.AngleOfSight to (Samurai.X, Samurai.Y)

    -----> Functions: Call Move_Attack (UID: UID, AngleOfMotion: Enemy.AngleOfSight)

    -----> Functions: Call PlayerGetsAttacked

    --------+ [DISABLED] Enemy: Is overlapping Samurai at offset (round(cos(Enemy.AngleOfMovement) × TileSize), round(sin(Enemy.AngleOfMovement) × TileSize))

    ---------> (no actions)

    // for some reason, it gives priority to MOVE>Attack, this "if" is to force it´s hand

    ----+ Enemy: [X] Has LineOfSight from (Self.X, Self.Y) angle Self.AngleOfSight to (Samurai.X, Samurai.Y)

    // if you can move to, do so

    --------+ Enemy: TileMovement can move to (Enemy.TileMovement.GridX + round(cos(Enemy.AngleOfMovement)),Enemy.TileMovement.GridY + round(sin(Enemy.AngleOfMovement)))

    ---------> Functions: Call Move_Forward (UID: Enemy.UID, AngleOfMotion: Enemy.AngleOfMovement)

    // if there´s an obstacle, try to go around

    --------+ Enemy: [X] TileMovement can move to (Enemy.TileMovement.GridX + round(cos(Enemy.AngleOfMovement)),Enemy.TileMovement.GridY + round(sin(Enemy.AngleOfMovement)))

    --------+ Enemy: [X] Is TriedToMoveThisTurn

    ---------> Enemy: Set TriedToMoveThisTurn to True

    // if its Left or Right

    ------------+ Enemy: AngleOfMovement = 0

    ------------+ OR Enemy: AngleOfMovement = 180

    ----------------+ System: Enemy.Y < Samurai.Y

    ----------------// Up

    -----------------> Enemy: Set AngleOfMovement to 90

    -----------------> Functions: Call EnemyMelee_MoveOrAttack (UID: UID)

    ----------------+ System: Enemy.Y ≥ Samurai.Y

    ----------------// Down

    -----------------> Enemy: Set AngleOfMovement to 270

    -----------------> Functions: Call EnemyMelee_MoveOrAttack (UID: UID)

    // if its Up or Down

    ------------+ Enemy: AngleOfMovement = 90

    ------------+ OR Enemy: AngleOfMovement = 270

    ----------------+ System: Enemy.X < Samurai.X

    ----------------// Right

    -----------------> Enemy: Set AngleOfMovement to 0

    -----------------> Functions: Call EnemyMelee_MoveOrAttack (UID: UID)

    ----------------+ System: Enemy.X ≥ Samurai.X

    ----------------// Left

    -----------------> Enemy: Set AngleOfMovement to 180

    -----------------> Functions: Call EnemyMelee_MoveOrAttack (UID: UID)

    // //if everything fails, just stand still

    ----+ System: Else

    -----> (no actions)

  • I would like to help but upload the file to dropbox or google drive first. Don't forget to grant/open access later.

  • thanks alextro

    I´m still kind of new to participating in forums and don't have all the proper "etiquette" ,next time I´ll just post the project :)

    I removed a lot of functions and behaviours trying to detect the problem, enemies have two states, "ready to move/attack" and "idle", they switch between them every turn.

    The function that's giving me trouble is "GetAngleOfSigth", in the event sheet Enemies, under the group ranged, as I said, it works great EXCEPT when the player is straight up at 90°, it try feeding that variable directly to check if it´s that the function isn't working properly, but that´s not the case. It just acts as if it cant the the player.

    Any insight is welcomed

    https://drive.google.com/drive/folders/1DYgKzNhHXuw-rgVvdAwvKYAmzzU-kd8s?usp=sharing

  • Shame on me. I couldn't fully modify your project since I no longer have C3 subscription. However I investigated that the problem lies in event 55 'Pick instance with UID'. When I disabled/remove it, north and south enemy both able to attack. So my conclusion led to how many UID were switching to that specific event execution.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • alextro Hi! I´ve been working on other systems, but I just tried delating line 55 in "Enemies" but I still get the same mistake :/ tried in two different PCs in case it was some weird mistake, but it still doesn't work.

    thank you nonetheless

  • I would like to test the LOS behavior on my own by replicate similar battle system of yours to check whether things up to expectation.

  • alextro I had to stop to keep for work, but I´m about to re-engage this project, I´ll keep you posted if I find a solution!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)