Jump to content

Recommended Posts

Posted

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()?

Posted

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?
 

Posted

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)

Let's build cool stuff and have fun. :)

Posted

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.

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.

×
×
  • Create New...