How do I get the position of the object I'm colliding with?

0 favourites
  • 10 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • HI,

    I want my NPC move away from another NPC of the same type it's colliding with (without turning away) and for that need to get the position of that 'other' NPC. how do I best get that position on collision?

  • Hi ,

    on collide , take the position x and y of the interested object.

  • yeah but how do i reference the object I'm overlapping with?

    especially when the two objects are of the same type

    say i'd go

    on Event: NPC_Blue overlap with NPC_Blue

    action should be:

    Move X pixels at angle NPC_Blue.position - otherNPC_Blue.position

  • overlap or collision will work the same.

    make sure your collision box is set.

    one thing to remember that the OnCollision event will happen every tick (60 ticks per second) and it will select every object of the same type. And once the event is triggered, that also "picks" that object. So when you reference the object in the Actions, you are only referring to the object that triggered that particular collision.

    The problem with checking collisions with the same object is that you aren't assured which Object you are getting(picking).

    See my test capx

  • The problem with checking collisions with the same object is that you aren't assured which Object you are getting(picking).

    See my test capx

    thanks for putting this together, seems to work nicely.

    Problem is, like you're saying, I can't be sure which object is referenced.

    What I want to use this for is to seperate two colliding objects, while not changing their overall movemn tdirection (like bounce would). this doesnt seem to work this way, as i can't make sure that I can get the correct direction, away from the 'other' object in the collision.

    Is there a better way to move overlapping objects away from one another without rotating them?

  • This also depends a lot on the freedom of movement of your enemies, If they are restricted to a motion on one axis, you could change there movement speed on overlap at offset for a few moments and then return them to their normal speed..

    This will offcourse only work if the enemies are moving in the same direction..

    If they are still overlapping after a certain amount of time you could choose to change the direction anyway..

    Easiest way to achieve any of this is to have a family with just the one enemy and check the families overlap with the enemy, I thought that way you can actually reference both instances..

    For families you need the paid version though..

  • aha, could you elaborate on the "change at offset"-idea?

    I have an enemy(-family) that moves only through a bullet behaviour. they'll be moving in similar but not identical directions towards the player.

    I want them to avoid overlapping by doing a sidestepping-kinda movement while still approaching the player. I don't know how to determine the "away" direction relative to the object I'm colliding with.

  • While working on an example I got this one..

    Although it's not exactly what you asked for, it has possibilities..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thanks for the example!

    yeah, I was thinking of that sort of approach, wiggle the enemy and hope that it solves the overlapp eventually. sadly it looks just as uncoordinated

    Is there really no way to accurately keep two moving objects from overlapping?

  • Ofcourse there is, there's always a way..

    First you have todecide what is and what isn't acceptable for the objects to do when trying to avoid collision..

    A car brakes really hard, a person on foot jumps out of the way, another possibilitie is to go slightly in another direction and pick up the orginal direction afterward..

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