Function Call Weirdness

0 favourites
  • 8 posts
From the Asset Store
Basic clone of a 80's arcade game called Gyruss that was quite fun to play!
  • I decided to move all the asteroid destruction/splitting code in my game to a single function that will be called whenever one of the following occurs:

    • Player ship collides with asteroid
    • Enemy ship collides with asteroid
    • Player bullet collides with asteroid
    • Enemy bullet collides with asteroid

    However, I am now getting a weird issue where the asteroid sometimes splits correctly, and other times does not split at all. I'm not sure if this is a function problem or a rendering problem, because I am also having weird issues where 'invisible asteroids' collide with my ship despite the fact that they never rendered on the screen.

    Here is the function in question:

    <img src="http://i.imgur.com/Rsgx1ly.png" border="0">

    ImpulseCollision.capx

    Can anyone help me out? I'm confused as to why this is happening after I moved my code to a function call. Is it possible for the function to be called multiple times? Say both the player bullet and the enemy bullet hits an asteroid. Previously, the code that is now in the function would have been duplicated as an event chain for the player bullet -> asteroid collision and the enemy bullet -> asteroid collision, but now both collisions will call the same function.

  • I believe that Functions act within their own scope - that is to say, they don't respect any picked objects at the point the function was called.

    So, your function is currently being applied to every asteroid whenever it is called. Is that really what you wanted?

    If you want to apply the function to only a specific asteroid, you can pass in its UID as a parameter to the function.

  • People and their beta version capx files!

  • Here you go:

    <img src="http://dl.dropbox.com/u/19921470/asteroid_collision_fix.PNG" border="0" />

    I highlighted one odd line, why are you taking velocity from seemingly random object? :)

    You need to pass the UID of colliding asteroid as parameter to the function, as visibility of picked objects does not carry into functions.

    Some random general notes about the whole project that might help you in the long run:

    You should definitively look into using families, soon you'll project will become very hard to manage as it grows bigger and bigger. For example, you could have family 'Bullets' which has Friendly and Enemy bullets. Then you could check for asteroid collisions for bullets without having to do separate events for all bullet objects.

    You have lots of variables that you could use inbuilt functions for; for example EnemyCrescentCount could be replaced by using EnemyCrescent.Count which returns numbers of instances that exist in the layout. Keeping manual variables like that up to date can become tedious :)

    You are making good progress with your project, keep it up! It's looking great! :)

  • Thanks Vee!

    I actually found out the problem is one line right above where you highlighted. Layer 0 = background layer, not the active game layer! So I changed it and now things are working more normally.

    You are right that I should be passing in the object that is colliding with the asteroid and not just some random object. What I have is currently a result of copy-paste and not much refining yet. I should add a parameter to the function that affects the physics. However, I honestly do not see the physics library having much effect on my game objects. A lot of the in-game physics, such as the 'bounce' that occurs whenever a player ship collides with something, is done manually via CustomMovement because the physics library doesn't seem effective.

    To be frank, there's a lot of weirdness going on that I'm not sure of. For example, the enemy ships have the Wrap behavior, but they don't wrap so I had to include my own wrapping code.

    I've never heard of families in Construct 2, so I'll have to look them up. Right now I've been using groups, but the events sheet is getting really large so anything I can do to cut things down would be appreciated. I've also recently noticed that some of the things I am manually tracking are also automatically tracked from the engine, so I need to redo the events for those things.

  • People and their beta version capx files!

    For the purposes of bug reporting, you have to use the latest beta version, otherwise you cannot submit a bug report because there is a chance it may have been fixed already in a beta release.

    Despite the disclaimer that beta releases are 'betas', the fact that they have fixed numerous bugs since the last stable release means they are probably more 'stable' in terms of non-new features than the latest stable release is!

  • Okay, I've modified the function calls so they pass in a parameter containing the asteroid's UID, this way all the asteroids don't explode when only one of them get hit.

    But now I'm having issues where sometimes asteroids you aren't hitting are splitting.

    <img src="http://i.imgur.com/OG3555U.png" border="0">

    ImpulseCollision.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Okay, I've modified the function calls so they pass in a parameter containing the asteroid's UID, this way all the asteroids don't explode when only one of them get hit.

    But now I'm having issues where sometimes asteroids you aren't hitting are splitting.

    <img src="http://i.imgur.com/OG3555U.png" border="0">

    ImpulseCollision.capx

    Check my screenshot earlier, you need to pick the asteroid UID you give to function via parameter. The event is right under the function trigger. I also made few other minor changes to the function. :)

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