How to make two of the same object turn around when colliding with each other.

Not favoritedFavorited Favorited 0 favourites
  • 10 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • To be clear the two objects in question here have the platform behavior. Also I should mention this isn't a singular object but rather a family which contains multiple enemies with the platform behavior. What I *want* to happen is for the enemies to collide with each other and then turn around. (So for example if one enemy was moving to the right they'll start moving to the left and vice versa.) A lot of platformers do this but I've been having trouble doing it myself for the past few months. Usually what happens is instead of both of them turning around only 1 will. I've tried putting them into separate Families or just manually doing x enemy on collision with family "Enemies", nothing works.

    Anyone know a better way to achieve this?

  • What you've described should work in theory so it must be a problem with event structure and picking. When an 'enemy' collides with 'family' then in actions you can apply to each individually with enemy actions and family actions to alter variables or make them swap directions and such. Try to keep as simple as possible at first and see if it works because other events can also interfere.

  • That's basically what I tried to do, no luck. These are the only events in the project that globally affect the Direction the enemies move in. And the Goomba in particular doesn't have any other code that would affect the their direction outside of these events.

  • fex.net/s/p2mabem

    Will definitely take a closer look later but this probably won't work for me... just because of the way the image points are positioned on the enemy's hitboxes causes them to teleport when mirrored like that. Though they seem to work fine with the normal Mirror behavior so I dunno might be something else

  • Will definitely take a closer look later but this probably won't work for me... just because of the way the image points are positioned on the enemy's hitboxes causes them to teleport when mirrored like that. Though they seem to work fine with the normal Mirror behavior so I dunno might be something else

    You didn’t provide any examples, and now you’re saying there are certain points that destroy the whole algorithm.

    It seems like wasting time—giving answers to people who are too lazy to include their own example of the problem in the question and provide a detailed explanation.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • >

    > Will definitely take a closer look later but this probably won't work for me... just because of the way the image points are positioned on the enemy's hitboxes causes them to teleport when mirrored like that. Though they seem to work fine with the normal Mirror behavior so I dunno might be something else

    You didn’t provide any examples, and now you’re saying there are certain points that destroy the whole algorithm.

    It seems like wasting time—giving answers to people who are too lazy to include their own example of the problem in the question and provide a detailed explanation.

    It wasn't laziness I just didn't have time to test much.

    I just did now, however and yes, I was right about it being the image point. If I center the origin point there's no teleporting shenanigans, however if I keep it as is that's when it starts teleporting. And to be clear as it is currently it's at the top left corner of the sprite so it lines up with my tiles.

    When it's flipping the width it's sending it a tile back/forward because... well you know like I said how the image point is placed. I don't want to move the origin point because it'd mess up other code and make me have to redo level layouts. It's a pretty big hassle. Also the enemies stop when colliding with each other currently because of the way I set everything up but this is something I could fix myself since I know what's causing it (I think so at least). I posted my code above if that'd help at all.

    I don't know why mirroring works fine but flipping the width manually doesn't, unless I'm misreading the code, which I probably am.

    Also I'm confused why you thought I didn't include an example of the problem? I did say it was probably the image point earlier. Unless you mean like a video or something but I don't really think that'd help that much.

  • I can see the issue why it won't turn, you need an Else. When you set direction to 0 the condition below becomes true and it sets it back to 1. It is a common problem that crops up because the user thinks of it as an if/else but Construct actually runs the first condition then the second one because it became true from the first one, adding the Else direction=0 instead means it becomes a true if/else statement when triggered.

  • Yeah, I was just about to come back and say I noticed that lol

    There were a few other issues I had to iron out (enemies would now stop contact with a wall) but in the end it works now. Thank you both for your help, sorry if I was being annoying about it

  • Yeah, I was just about to come back and say I noticed that lol

    There were a few other issues I had to iron out (enemies would now stop contact with a wall) but in the end it works now. Thank you both for your help, sorry if I was being annoying about it

    Good that you managed to solve the problem!

    That’s why sometimes a screenshot isn’t enough—both in the project and in the objects themselves there’s a lot that can affect the game, so having a complete example is important for helping.

    And “being annoying” isn’t a problem at all—we all love creating games here, and our engine Construct 3, so a lot of discussion and clarifying is normal and even helps development!

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