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

Get help using Construct 2

Post » Wed Jul 16, 2014 8:49 pm

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?
Last edited by facecrime on Wed Jul 16, 2014 9:34 pm, edited 1 time in total.
B
12
S
5
Posts: 207
Reputation: 1,672

Post » Wed Jul 16, 2014 9:05 pm

Hi ,

on collide , take the position x and y of the interested object.
Hire or Offer a project

Portfolio

Scirra new Shop
B
34
S
5
G
1
Posts: 118
Reputation: 2,663

Post » Wed Jul 16, 2014 9:32 pm

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
B
12
S
5
Posts: 207
Reputation: 1,672

Post » Thu Jul 17, 2014 2:31 am

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
You do not have the required permissions to view the files attached to this post.
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Thu Jul 17, 2014 8:01 am

jobel wrote: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?
B
12
S
5
Posts: 207
Reputation: 1,672

Post » Thu Jul 17, 2014 8:59 am

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jul 17, 2014 9:55 am

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.
B
12
S
5
Posts: 207
Reputation: 1,672

Post » Thu Jul 17, 2014 11:06 am

While working on an example I got this one..
Although it's not exactly what you asked for, it has possibilities..
You do not have the required permissions to view the files attached to this post.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jul 17, 2014 8:27 pm

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?
B
12
S
5
Posts: 207
Reputation: 1,672

Post » Thu Jul 17, 2014 8:42 pm

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: mikehive, plinkie and 8 guests