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.