Get the angle between two instances of the same object?

Discussion and feedback on Construct 2

Post » Fri Jun 20, 2014 1:53 pm

How would you go about getting the angle() between two instances of the same object when they overlap? I'm having difficulty isolating each of them. I want it so that when they overlap, they are moved a couple pixels directly away from each other. I figured that if I get the angle() between them and move one in a positive and the other in a negative direction, that will separate them.
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Fri Jun 20, 2014 2:16 pm

This is easier with Families, but without, you need to Pick the first, cache it's X,Y, then Pick the second, get the angle, calculate the two angles, change Two, go back and Pick One, and set it's angle.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
21
G
220
Posts: 3,648
Reputation: 123,725

Post » Sun Jun 22, 2014 3:17 am

@Blackhornet Weeellll, it turns out the two objects in question are mobs in the same family. How does that change things?
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Sun Jun 22, 2014 5:08 am

Families let you reference the same object separately. Just make a duplicate of the family, in this case, and use the duplicate for collision detection. Two lines of code instead of 9.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
21
G
220
Posts: 3,648
Reputation: 123,725

Post » Mon Jun 23, 2014 1:31 pm

@blackhornet Hmmm, so if the same sprite is in two different families, and an instance of the sprite collides with another instance of the same sprite, it will trigger an event as a collision between a member of family A and family B? I loaded up your double family example and maybe I'm reading it wrong, but it seems to show a collision between two *different* objects from the same family? I will experiment a little...
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Mon Jun 23, 2014 1:37 pm

@blackhornet Oh, I see what you did. I hadn't looked at the first example, so I was confused by it's presence in this example, plus the two different animation frames for the same sprite. I get it now, so like I said in the above post. That's awesome, and much simpler. Thank you Blackhornet!
B
11
S
4
G
1
Posts: 159
Reputation: 1,803


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 6 guests