Should be easy find Z on a ramp with x and y (SOLVED)

Started by
21 comments, last by before-it-was-popular 12 years, 1 month ago
I need to find the players z if he was standing on an isometric ramp. I know the isometric tiles width and height (if it was square) and using Pythagorean I can get the ramps length. I just cant figure out what his given z would be.
Advertisement
If you know the Z of both the top and the bottom of the slope, you can do simple linear interpolation. Note that if your slope is parallel to one of the axes (X or Y), you don't need the other one for the equation

minZ+(maxZ-minZ)*((X-minX)/(maxX-minX))

At least I think that's right off the top of my head. You use the X position to find the percent (0-1) across the tile you are, and multiply it by the height of the tile. The adding of minZ and subtracting of minX are just because the tile isn't located at (0,0,0). Hopefully that made sense...
Hrmm not sure exactly what you are saying. I shouldn't need a minx miny or minz. I guess my drawing is kind of confusing. Let me try to explain better. All of this is within one block. Think completely local coordinates. So the far top left (outside the isometric square) would be 0,0. For the sake of simplicity lets say the max x for the block is 88 the max y is 44 and the max z is 60. again for simplicity lets say the player is at 88,22(the right tip of the diamond) how do I find his z. obviously his z would be 60 but I need an algorithm that considers any possible point in the diamond.
Is there any reason youre working with screen coordinates instead of block coordinates? If the sides of the block were parallel to the X/Y axes thhe math is much simpler.
The game is 2d and the entire engine is written that way.
I'd recommend you split the diamond into two triangles and interpolate the height across it. I haven't done this sorta thing in a while, but I can probably find the code in a few hours... I'm having trouble remembering how it worked off the top of my head. Google how colors are interpolated over triangles in renderers.
There has to be an equation to find the z. I can find the length of the ramp and any length of any lines in the block. Do i need to get the angle of the ramp and do something with that?
Sorry I cant find the code, but the idea should still work. Find the Z at both sides of the diamond for whatever Y value you have by interpolating the Z at the corners, and then interpolate between the two sides depending on the X value.
sorry I don't understand can you give me an example equation.
Finding height along top left edge:

Leftsidez=TopZ+ (leftz-topz) *(y/midY) ;

Top right:
Rightsidez=Topz+ (rightz-topz) *(y/midy) ;

Interpolate between left side and right side:

Z=Leftsidez+ (rightsidez-leftsidez) *(x/maxX)

(midy=maxy/2)

I think that's all right, off the top of my head. If y> midy, switch top with mid and mid with bottom.

This topic is closed to new replies.

Advertisement