Important issue about a flying enemy

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hi, I've ran into an issue related to a flying-enemy which I believe is significant to look into.

    Before I begin to explain it, the enemy consists of a bird that flies in the sky, impersonating as a common background element, but when the player passes under it, the bird plummets down below at quick speeds crashing to the ground, and then gets up again and turn in the opposite direction, this is the "core" idea.

    This works perfectly well (although it's not very polished yet), the problem is when the bird gets up. I'm using a "wake up again" timer that initially causes the bird to gradually move upwards, and after then sets its state value to 4, that causes it to stop moving. It kinda works, but it doesn't take into account if when the bird goes over the Y position where he was before falling, since it's just using a timer value.

    Now, I guess you could say that I could solve this quickly by setting an initial Y position value of the bird at the start of the frame and then checking to see if the Y position upon moving up is lower than that value. But I've tried that and although it works better than using the timer, it's kinda very janky as it bugs sometimes and doesn't work as intended.

    I could give an MFA or even a simplified version of this problem, as I think it's a deep issue that someone could understand better by looking at the code, if that's okay.

  • Usually, the solution for this kind of thing is to develop a formula that will position the object correctly no matter how many times the event fires by incorporating an "amount of elapsed time" value as the basis for the position of the object.

    In this case, you'd basically track how long the enemy has been in the intermediate state of moving up or down, and use that to calculate how far it "should be by now" based on starting Y and target Y.

    Hope this makes sense. Let me know if not and I'll try to clarify!

  • Thanks, I think I've got what you mean so I will try it, by any means (and so I go better with this), could you explain it in more detail? (Sorry if I sound a bit stupid, I'm usually embarrassed to ask for clarifications ;-;)

  • Here's an example that I hope clarifies the technique. Essentially, all movement of this type is based on three things:

    1. target time the movement should be complete
    2. target position
    3. starting position

    Then we spread the movement over the time allowed by using a formula to ensure that no matter how many frames per second the program runs at, we always arrive at the same target at the expected time.

    This is a little different from what I originally described, but essentially the same thing as time-delta based movement. I think this way of expressing it is easier to understand and frankly I couldn't whip up a delta-based example quickly enough haha

    Hope this helps!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!