Jump to content
  • Advertisement
Sign in to follow this  
MikeKan13

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

This topic is 2479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!