Jump to content

Terrain::GetNormal returns Vec3(0, 1, 0)


martyj
 Share

Recommended Posts

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?
 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...