martyj Posted November 22, 2017 Share Posted November 22, 2017 Whenever I call GetNormal(x, z) on the Terrain object, it returns the same Vector of (0, 1, 0) Any idea on how I can get a normal for the terrain at a given point without using Pick()? Quote Link to comment Share on other sites More sharing options...
Josh Posted November 22, 2017 Share Posted November 22, 2017 If the terrain is flat than that is correct? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
martyj Posted November 22, 2017 Author Share Posted November 22, 2017 Hmm, must have been the case. When I tested it with very rough terrain it works as expected. Maybe you might have some tips as to what I'm trying to solve? I'm working on a custom Character Controller to not use a lot of CPU. I'm trying to align an entity to the slope of the ground based upon its position. I plan on doing this in two phases. 1. If the Character is far from the player, but not far enough that it is clipped, I plan on using the terrain's normal for rotation. 2. If the Character is close to the player, use World::Pick to get the info based upon a possible model collision. To get the rotation for X and Z I do the following: Vec3 i = Vec3(1, 0, 0); Vec3 k = Vec3(0, 0, 1); double xAngle = 90-Math::ACos(i.Dot(terrainNoraml)); double zAngle = 90-Math::ACos(k.Dot(terrainNoraml)); this->GetEntity()->SetRotation(Vec3(xAngle, rotation.y, zAngle), true); I think the only thing left to do is to rotate the normal vector based upon the Character's rotation. Is there a better way to do this? Quote Link to comment Share on other sites More sharing options...
Josh Posted November 22, 2017 Share Posted November 22, 2017 You can get the slope of the terrain at any 2D coordinate. This is floating points in the world, not terrain vertices: float slop = GetSlope(x,z) Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
martyj Posted November 22, 2017 Author Share Posted November 22, 2017 The slope is always positive though. Depending on the angle between my Character and the Slope it could be a negative rotation positive one, or across the Z axis instead of the X, ect. Quote Link to comment Share on other sites More sharing options...
Josh Posted November 22, 2017 Share Posted November 22, 2017 AlignToVector? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.