Jump to content
  • Advertisement
Sign in to follow this  

Find angle between two Y positions...?

This topic is 4925 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

Didn't work... :/

Now the vehicle is more or less locked to the ground....
This is the code I'm currently using:

GroundLevel = GetAltitude(Pos.x,Pos.z);

Direction += GravityVector;
vector3d OldPos = Pos;
Pos += Direction*g_delta;

if (Pos.y < GroundLevel+Radius)
float angle2 = atan2(sqrt((OldPos.x*OldPos.x)+(OldPos.z*OldPos.z)),OldPos.y);
float angle1 = atan2(sqrt((Pos.x*Pos.x)+(Pos.z*Pos.z)),Pos.y);
TerrainElevation = angle2-angle1;

// TerrainElevation = 50; //should be AngleOf(OldPos.y,Pos.y);

Pos.y = GroundLevel+Radius;

Share this post

Link to post
Share on other sites
I'll look at your code more carefully in a bit, but meanwhile, are you missing any radian/degree conversions?

Share this post

Link to post
Share on other sites
Ah, I think you're trying to solve a different problem than I thought. Try this:

Vector3 v = pos - oldPos;
pitch = atan2(v.y,sqrt(v.x*v.x+v.z*v.z)); // You might have to negate this

I think pitch is what you're calling 'TerrainElevation'.

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!