Trouble with pseudo Z axis

For questions about using Classic.

Post » Thu Oct 02, 2008 11:45 am

Ok so I'm making a game/engine which is like 3/4 view using physics for collisions and i've put in jumping over and walking on top of obstacles right, but as soon as i have obstacles that have different 'heights' i run into problems.
So i have a familty called Terrain, and every object in the terrain family has a ZHeight variable which tells the game how high the object is and subsequently how high the player will have to jump to get over/on top of it.
The player also has a ZHeight variable that is obviously how high off the ground he is.
So i'm running this little loop:


(Don't worry about the subevent in there, it's not part of this context)

Looking at it you would think it should work fine, cause the objects in terrain have varying heights, a 'for each' should be the way to go. Yet, the collisions are not disabled, with the 'for each' loop there i can't jump over a single thing, so i take the 'for each' loop out, now i can jump over things but it treats them all as the same height. It's quite frustrating. I'll upload the exe so you can see what's going on

[url:12sktsub]http://www.mediafire.com/?cd3zklmnngi[/url:12sktsub]
You'll have to ignore the sprite laying for now, i'm also having trouble ordering the layers by ZHeight THEN by Y coordinate

controls:
WSAD + mouse - move
Space - jump
E and Q - go in and out of slow-mo (soon to be upgraded to super speed once/if physics velocity is pixels per second) currently mostly used for helping find bugs.

Anyway, is this a bug with families and disabling physics collisions? or is there a better way to code this? I dunno, anyone got any ideas?
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Thu Oct 02, 2008 12:16 pm

After running a little test it would appear that "Reset disabled collisions" resets all disabled collisions for that object. What's happening here is your tallest obstacle, when it is reached in the loop, is resetting the collisions for your sprite because, well... it's tall and your only picking criteria is tallness. This is why it was working when everything was the same height.

Try reversing the order of the objects in your "disabled collisions" actions. So instead of saying:

Controller: Disable physics collisions with Terrain

do this instead:

Terrain: Disable physics collisions with Controller

That way each collison disablement is local to the Terrain instance instead of global for the Controller. If that makes any sense.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Oct 02, 2008 12:28 pm

Deadeye, you're a genius, i've got it to work now, although i had to change the else statement to another 'for each' loop, but i can now try to change it so it works a little better
Thanks! just when i was beginning to think nobody read my threads lol

So now, maybe someone here might know, now that my height problem is out of the way, i wanna know how i would do the ordering of sprites, i've tried the 'for each' ascending by Y coordinate thing, which worked great until i introduced the pseudo Z axis.
I now need to be able to order by Y coordinate AND the ZHeight variable, with higher ZHeights being on top but still being put behind or in front of objects of the same ZHeight if you catch my drift.

Save me deadeye!
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Thu Oct 02, 2008 12:57 pm

Oh man, I think you just broke my brain :shock:

I'm sorry, I haven't even the faintest clue where to start on that one. I keep thinking a nested loop to sort by z in side of a loop to sort by y might do it (or vice versa, I don't know), but when I try to picture it running all I get is a headache. And to test something like that out I'd have to build my own pseudo-3d thingumer too and... bleah, that's too much work.

Hopefully someone else has some good ideas for you though.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Oct 02, 2008 12:58 pm

Yeah i just attempted a nested loop similar to what you said, so far it only does the typical Y coordinate one though :( thanks for trying though
i could send you the cap if you want to try a few things with it
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Thu Oct 02, 2008 1:04 pm

Well okay, I'll give it a shot but I can't promise anything. And I won't be able to get to it until tomorrow, I should have been in bed hours ago.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Oct 02, 2008 1:08 pm

rightio, shoot me a pm with your email or something in it later
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Thu Oct 02, 2008 1:54 pm

'ELSE' doesn't make sense after a 'For each' loop - 'For each' is actually logically false (because of how the engine works), so I think the else event will actually run like an 'always' event.

I think the best way to handle Z ordering is to come up with some combination value: if you loop by .Y + .Z ascending or something, it might be able to factor in both. I think you'll need to tweak that expression a fair bit to get it right though...
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Thu Oct 02, 2008 2:06 pm

Yeah i've got the loop fixed, the only problem now is the proper sprite layering, i'm stumped

EDIT:
ok so i had an idea that might come closer to working, i've done something like this

for "layers" from 0 to 64
(sub)for each (family blue) ordered by Y acsending
(subsub)Blue.Value('ZHeight') is equal to loop index of "layers" - send to front

it -kinda- works but not really, any help?
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Post » Thu Oct 02, 2008 4:50 pm

do you want an object with a higher Z to always be on top of one with a lower Z regardless of Y value, and only sort it by Y value if Z is equal

surely you can just do (pretty much what Ashley said)
for each object ordered by .y+.z*9999999999999999999999999
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests