# Calculating Y Position

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

## Recommended Posts

I have a tad of an issue. I am wanting to calculate the Y position a character should have. This character needs to be able to walk on land, climb up land and go down slopes. Right now the character is being moved across a plane whereas the scenery and plane are in a static position. I can easily get the Y position of the character, but I need to get the Y position of the point where the character is over. D3DXIntersect() isn't working too great so I am looking for an alternative.

##### Share on other sites
Actually the question is more along the lines of; How would I go about getting the Y position of a mesh face.

##### Share on other sites
I'm in quite a hurry (it's 9pm and I'm still at work [headshake]) but to get you started you probably want to look at the plane equation (searching Wolfram's 'MathWorld' website is usually a good start).

aX + bY + cZ + d = 0 works for triangles (which are convex and coplanar) and can be rearranged accordingly. Working out the plane equation from a point and a normal vector is easy but even easier if you use D3DX. Once you have the coefficients you can plug in the known values (e.g. X and Z) and rearrange for the unknown - Y - and you're sorted.

I can move this to the 'Maths & Physics' forum if you'd like a better explanation?

hth
Jack

##### Share on other sites

What I mean more then anything for starters is getting the base point under my character so gravity has no effect. I understand the equations of planes e.g. Ax + By + Cz = D even to do that I would require 3 points and not being able to even get one it wouldn't help.

This is a DX question more then anything. I was pretty sure using D3DXIntersect() I could get it working because I have before; Out of no where it stopped working.

Lets say I have a plane

20 x 20 which is located at 0, 0, 0

Now I have a camera located at

-1, 0, -1

The camera should fall off the map if treated with gravity correct? How do I detect if the object is still on the map - not using bounding boxes or any of that junk because the plane can be unevenly formed or curved making the character unable of traversing upwards.

Example code would help probably most.

Thanks.,

##### Share on other sites
Quote:
 Original post by Dave84311I have a tad of an issue. I am wanting to calculate the Y position a character should have. This character needs to be able to walk on land, climb up land and go down slopes.Right now the character is being moved across a plane whereas the scenery and plane are in a static position. I can easily get the Y position of the character, but I need to get the Y position of the point where the character is over.D3DXIntersect() isn't working too great so I am looking for an alternative.

If you want to use D3DXIntersect() to get the vertical distance (in world Y-axis direction) from an irregular terrain mesh, you could do something like this:

   D3DXVECTOR3 vRayDir ( 0.0f, -1.0f, 0.0f );  // vertical, from top to bottom.   D3DXVECTOR3 vRayPos; // the character's center, for exemple.   BOOL Inters; // TRUE if the ray intercepts the terrain.   FLOAT pDist; // distance between vRayPos and the terrain (in vRayDir direction).   D3DXIntersect( mesh,         // terrain mesh                  &vRayPos,                  &vRayDir,                  &Inters,                  NULL,                  NULL,                  NULL,                  &pDist,                         NULL,                  NULL );   if ( Inters )   {       // Supposing no gravity and the character's center is 100 over the terrain. So, the character could follow the terrain surface by doing this:       centroPerson.y = centroPerson.y + (100 - pDist);   }

I hope it helps.

##### Share on other sites
Yes, I wrote something similar to that, I plugged in the characters position 0, 0, 0 when at that coordinate. However when walking no change occurred. I'm not sure if me not setting my character far above or below the map has anything to do with it. It worked before but oddly it stopped working a couple days back when adding newer components. After two days of messing with it I decided to post here.

Anyone know why it wouldn't work or where I should set it.

##### Share on other sites
I now know why it doesn't work. We imported new models for our game, the map however has only certain faces that can be checked for intersections. Now I am going to have some fun trying to find out what side does what.

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631778
• Total Posts
3002308
×