User Tag List

Results 1 to 8 of 8

Thread: Hitbox for randomly spawning enemies

  1. #1
    Clicker Fusion 2.5
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)

    Join Date
    Nov 2014
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hitbox for randomly spawning enemies

    Hey everyone!

    For the past few months, I've been trying to figure out a solution for a problem I'm having (anybody in the almightyzentaco Discord, may have seen me bring this up). I've been trying to do some tweaking on a project that I've been hard at work on for a few years, and though I'm almost finished in many aspects, there's one thing that has me stomped. See, this game works just fine on the PC, but I want to have a mobile version as well, and that's where things get messy. I have it set up to where enemies spawn every so often and you must tap (or click) on them to destroy them. At first I had no hitboxes for these enemy objects, as the collision worked just fine on the PC. It was only when I tested the level out on mobile, that I realized that I couldn't tap certain enemies (they vary in size).

    I didn't want to try to implement hitboxes so late in development, as it would take a lot of time, but I realized there was no real way around it, so I set about doing just that. And this is where's where the headache began...here's a brief rundown of what I'd done.

    Firstly, upon implementing the hitboxes, I noticed right off the bat that not only was everything a completely scattered mess visually, upon clicking on one hitbox, nearly all of the enemies on screen would get attacked or destroyed or nothing would get destroyed.

    So I figured doing a Spread Value (both the sprite and hitbox set to 0) would fix some of this and it did...sort of. I was able to get the hitboxes and sprites to position just fine. But there was still some other aesthetic issues, such as some of the sprites facing in a direction that was opposite of where its respective hitbox was moving (i.e. hitbox moving the left, and the sprite facing right). With some help, I was able to resolve the sprite directional issue. But there's still the issue of both the hitbox and sprite not getting destroyed when being tapped/clicked. What also happens is that sometimes merely the hitbox is destoryed, but never both the hitbox and sprite. The tap/click is registered, since the score increases as it should, but I'm not getting the result I'm looking for.

    TL : DR what I want is to spawn enemies every "x" amount of seconds, and tap to destroy each one (thus scoring). Initially no hitboxes were used, since everything worked fine without them, on the PC. Porting to mobile is where I realized hitboxes were necessary, and now the the enemy behaviors are completely in a disarray, due to the hitbox collision not registering, as well as the aforementioned aesthetic issue of the sprites not facing the where the hitbox is moving.

    Here's some screenshots from an example MFA (I always whip up dummy MFA's, when I run into certain issues, so as not to further destroy the actual project lol)

    2017-12-04_4-12-03.jpg

    2017-12-04_4-12-46.jpg

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    DaveC's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Australia
    Posts
    2,031
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Random question - why are hitboxes necessary on mobile devices? have you tried turning off "use fine detection" for collisions in the objects properties?

  3. #3
    Clicker Fusion 2.5
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)

    Join Date
    Nov 2014
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm. That's an interesting point. I suppose I figured that if the taps weren't registering on, then hitboxes would've been the answer. Although I'd made it this far without them.

    As far as turning off Fine Detection...To be honest, I'm not sure if I've tried that or not, as it's been about two months since I've last touched this thing (I needed a break), annnnd I've misplaced some of my notes. I can try that when I get home though, later this morning. I would love for that to be the fix for this.

  4. #4
    Clicker Fusion 2.5
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    zip2kx's Avatar
    Join Date
    Jun 2015
    Posts
    583
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So your only problem is the direction of the sprite?
    You solve that by doing a simple

    Sprite id = hitbox id
    ---> Set direction of sprite to hitbox dir

    It's no different than having a player hitbox and sprite

    edit: i read wrong sorry, with the destruction you can do a check in various ways. You can loop through them all and check if both object have the same ID, if not delete. The simplest way might be to do something like this:

    Sprite isnt overlapping Hitbox
    ---> Destroy sprite

  5. #5
    Clicker Fusion 2.5
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)

    Join Date
    Nov 2014
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by zip2kx View Post
    So your only problem is the direction of the sprite?
    You solve that by doing a simple

    Sprite id = hitbox id
    ---> Set direction of sprite to hitbox dir
    So does this also work if the objects are moving in various directions, as opposed to just one direction?

  6. #6
    Clicker Fusion 2.5
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)

    Join Date
    Nov 2014
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh, another issue I forgot is the tendency for two like objects to stick together. More specifically the ones that have hitboxes.

  7. #7
    Clicker Fusion 2.5
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    zip2kx's Avatar
    Join Date
    Jun 2015
    Posts
    583
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your main issue seems to be that you need to match objects together. That spread value approach is valid but it sounds like your matching segment isnt working.

    start of frame
    ->spread value in alt a of hitboxes
    ->spread value in alt a of sprites

    Sprite id = hitbox id
    ---> Set position of sprite to hitbox
    ---> Set direction of sprite to hitbox dir

    That should in theory match them all up and separate them so they can move individually.

  8. #8
    Clicker Fusion 2.5
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)

    Join Date
    Nov 2014
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My apologies for the delayed response. I've been in the hospital. Bleh...

    Anywho

    zip2kx
    , I tried exactly what you said, and that seems to work perfectly so far. What I did was

    *ID ("Hitbox") = ID ("Sprite")
    **(Sprite) : Set position at (0,0) from ("Hitbox")
    **(Sprite) : Set direction to Dir ("Hitbox")

    and on the PC, it works like a charm. I've yet to try it on mobile just yet, but I will test that out this evening.


    Now why is it that the objects with the hitboxes just seemingly appear out of thin air? I had a spawn point offscreen, but they don't seem to come from there anymore. This evening, I can double check to make sure I actually set the hitboxes to use that spawn point. It's possible that I didn't re-do the events to have this happen, but I'm almost positive that I did.

Similar Threads

  1. Help with enemies walking randomly on the ground
    By DillonKun in forum Fusion 2.5
    Replies: 3
    Last Post: 14th June 2017, 10:32 PM
  2. randomly spawning and dissappearing objects
    By nex86 in forum Fusion 2.5
    Replies: 7
    Last Post: 17th November 2014, 08:02 AM
  3. How to make enemies attack randomly like age of empires?
    By denis6555 in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 27th May 2014, 02:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •