Yeah, but that's what I was talking about.I was just joking. My humor tends to very dry.
Terrain.activeTerrain.SampleHeight(vector3 location) returns the Y of the terrain for any Vector3 passed to it. Therefore:
C#:public int GetGroundDist(Vector3 location) { return Math.Abs(Terrain.activeTerrain.SampleHeight(location) - location.y); }
That method gets the player distance to the Terrain distance but what people usually uses is the Player distance to what he has below.
I've been doing lots of testing with Raycast and reached a way to get what a player has below.
---
The problem is that if you stand on a corner, with more than half of your body out, you don't fall but if you raycast on Vector3.down you don't hit the corner, so returns a big distance, like if you were standing still on the air.
I was looking on something to this and still testing going on but seems fine. I'll post results when I finish.
But that's another story.
---
Well what I'm using to get the player distance is something like :
C#:
RaycastHit[] allhits = Physics.RaycastAll(pl.Location, Vector3.down, Mathf.Infinity);
foreach (RaycastHit hit in allhits)
{
if (!hit.transform.name.StartsWith("Player", StringComparison.Ordinal))
{
float hitdist = hit.distance;
if (hitdist < dist)
{
float floordist = hitdist;
}
}
}
By investigating I've found that you hit your own hitbox, and the hitbox name uses the format :
Code:
"Player" + name + "(" + id + "):player_soldier"
So here you have, my investigation resumed. I'm using this on the server side anti cheat that I've been working these days and seems to work pretty good.