Page 1 of 1

Zdepth admiting defeat need serious help!

PostPosted: Thu Jul 09, 2009 5:31 pm
by jimmynewguy
i saw this zDepth auto matic setter code on the wiki, which works....unless the screen is moving.
Code: Select all
void stackit(){
ChangeZDepth("Event Actor", ((y/120)+1)*.5);//120 is half my view size
              }

i'm pretty sure this can be solved with screen_to_actor, or actor_to_screen, i've never used either so wich one should i use and how. Or is there an easier/better way? I tried zdepth based off collisions, but they mess each other up butting walls in front of bushes that sould'nt be there. So can any one help before i pull all my hair out? :lol: Please and thanks to all
PS: (SORRY OZCENTRAL)

Re: Zdepth admiting defeat need serious help!

PostPosted: Thu Jul 09, 2009 7:18 pm
by Fuzzy
Try this:
Code: Select all
ChangeZDepth("Event Actor", (y*0.5);


Two things:

Zdepth: not limited to a range of 0.0 to 1.0. It just looks that way.

Always, always use a 0 before a decimal place. It works without, but that is bad coding practice.

the reason you are having trouble is because 1/120 is 0.0083333.

look at the sequence

1/120 = 0.00833333
2/120 = 0.01666666
3/120 = 0.02500000
4/120 = 0.03333333

Stop! See a problem? Round off the last two digits.

0.0250000 becomes 0.03 (rounding up)
0.0333333 becomes 0.03 (rounding down)

That is, no jokes, called a number collision. It will break your pixel collisions.

It might not happen with those specific numbers, but you can see what I mean, right?


60/120 = 0.50000000
61/120 = 0.50833333
62/120 = 0.51666666

You can see that it gets worse. All of those could round off to be 0.5 Zdepth. You cannot count on a float to retain precise values.

Can you avoid even the *0.5? If you dont need precisely 120 zdepth levels, you can avoid that little bit of math. Just use the y value alone.

So there you go. You are not defeated. In fact, you can see that the solution simplifies your code. This is often how it works. If something doesnt work right, there is probably a simpler way to do it.

And it always pays off to ask for help.

Re: Zdepth admiting defeat need serious help!

PostPosted: Thu Jul 09, 2009 9:02 pm
by jimmynewguy
this doesn't work, everything just seems to dissapear, it goes behind the ground actor who's zDepth is 0....

EDIT: I use abs() to make them not always 0 that was one problem, but it only seems to work on some actors not others(even colnes) so ill look into it and see what i can do :) thanks

Re: Zdepth admiting defeat need serious help!

PostPosted: Thu Jul 09, 2009 9:13 pm
by jimmynewguy
ok found the problem......tiles.......awesome....idk how im going to make this work now.....i hate zDepth :| there is no way to fix this (or is there)....great :cry:

Re: Zdepth admiting defeat need serious help!

PostPosted: Thu Jul 09, 2009 9:38 pm
by Fuzzy
What didnt work? I just tested that an actor at 1000 zdepth appears in front of an actor that is at zdepth 0.0.

Re: Zdepth admiting defeat need serious help!

PostPosted: Thu Jul 09, 2009 10:25 pm
by jimmynewguy
if you have a tile like a wall persay when you tile it like --------- here

--------- and here

the y is where ever the first tile was, so it messes up the whole thing