[Solved] How do I use LOS with Family of same objects?

Get help using Construct 2

Post » Fri Feb 27, 2015 11:33 pm

I've read everything I can find on picking Family instances and I honestly don't see how I can do this...

I can't pick two Fighters in same "Fighters" Family, determine if the first Fighters has LOS to second Fighters, then if second Fighters.IsFoe (inst var) is True, set second Fighters to visible. I tried the two families trick, Fighters_1 and Fighters_2, this could work if you were allowed to have the same Fighter.Foe inst var on both families. But you cannot.

I think this may be impossible in C2 :cry:
Last edited by locohost on Mon Mar 09, 2015 11:28 am, edited 1 time in total.
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Mar 01, 2015 2:08 pm

I don't think this one is going to happen :-(
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Mar 01, 2015 3:02 pm

There are no easy way to do it in C2, at least that I know of. But there are lots of way you could go about it regardless.

For instant what I can just think of might be the easiest is to make a dummy sprite. Then right before you have to check for LOS you set dummy position to the to the target position and then you store the UID of the target Fighter with the dummy so you can easily pick it again later should you need it. Then you check LOS vs the dummy instead.

Or you can do it the other way around which is probably even better, set the dummy to the one you want to check LOS for, and then do a:

Dummy.Test_UID = Fighter.UID

Fighter.UID <Not equal> Dummy.Test.UID //That will select all fighters except the one you want to check LOS for.

Dummy check LOS to Fighters

That is two ways to go about it, the last one is probably the best one in my opinion.
B
44
S
11
G
2
Posts: 1,177
Reputation: 6,783

Post » Sun Mar 01, 2015 4:41 pm

The dummy sprite idea is pretty good. Had not thought about that. Thank you @nimos100 !
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Mar 01, 2015 8:27 pm

locohost wrote:The dummy sprite idea is pretty good. Had not thought about that. Thank you @nimos100 !

u can do this, create on the family sprites u have a uid variable, and when is created save that uid, remember the first uid of the main sprite u have on screen unless u delete it, then when u want to select 2 of them just call the last uid - 1 or +1 depends witch ones u want to choose, but i think there is a better way then that, to your problem not sure what u try to achieve, if u can do a small capx with a simple sprite family and code ur selection code of family we could fix it for u a bit :P
Image
B
62
S
19
G
67
Posts: 1,310
Reputation: 41,938

Post » Sun Mar 01, 2015 8:35 pm

When I move on of my game Tokens to a new spot, I want to check to see if an enemy Token is in LOS. If it is, set it to visible. My idea was to iterate every Token with Token.Foe = true and check LOS to just those tokens, skipping my own Tokens.

My compromise is I don't bother with checking LOS to just Foes. It's checks LOS to all Tokens. So mine as well. Which is fine for now, but it doesn't feel right :-/
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Mar 01, 2015 8:49 pm

@locohost

I wrote a tutorial a while back on picking instances within the same family.
https://www.scirra.com/tutorials/556/understanding-picking-with-respect-to-families

Here's a quick picture of how to do what you're asking:
Image

You have to pick instance A, and save the properties you need to temporary local variables, *then* pick instance B.

So this is what your code might look like:
Image
B
31
S
7
G
8
Posts: 232
Reputation: 6,214

Post » Mon Mar 02, 2015 11:48 am

@cacotigon I did read your tutorial. It's very good :-)

I suppose I was hoping for something not involving any dummy objects or extra variables. Appears they are necessary to do this.
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Mon Mar 02, 2015 2:13 pm

Hello everyone, hello Locohost,

I'm on this at the same time, trying to find a simple and clear way. So I tried different things, but I got half satisfaction cause it's a trick and not a native function of Construct 2. So in a large project, using tricks would be confusing.

In my project I got a general family of entity and I'd like them to be able to chase (chaze ?) or follow each other. Barely the same with your fighters.

If you find a cool way to do this, can you share it please ?

It seems like dummy object is a solution, but it involves creating more and more objects. Ok this dummy doesn't need cpu intensive calculation like collision, and it is invisible in the game, so no extra draw. In my project and because of the family behavior and the difficulty to make "complex" interactions between two members of the same family, I got lots of these kind of solutions. I came to Construct 2 with knowledges in programming languages and game programming. With an engine of your own, you can have references to two entities in the game inside the same function to apply modifications on both simultaneously. Hard to do that in Construct 2 without breaking the event system optimisation (lots of picking, and reset picking list), or doing something unreadable.

If you find a good solution, I'm in for sharing :)
Good luck and sorry for my english might be incorrect, not precise, or really strange sometimes.

Nabu
B
14
S
4
Posts: 108
Reputation: 1,279

Post » Mon Mar 02, 2015 2:22 pm

Hey @Nabu0001

I think the dummy object that has all the same attribs as the Fighter family is the idea. Then in the first Family Pick event, it will by my Fighter, I'll store his data in the dummy Fighter. Then in second Family Pick event, I'll be picking enemy Fighters. I think this should work and is not too much of a hack ;-)
B
13
S
4
Posts: 280
Reputation: 1,573


Return to How do I....?

Who is online

Users browsing this forum: Aluna, R0J0hound, radhaw, Yahoo [Bot] and 6 guests