- Home /
help to understand collision detection
hello! what i want do understand is how to detect collision without colliders.... what iàm doing now is this
vector3 playerPos = new Vector3 (playerPosition);
Vector3 planePos = new Vector3 (planePosition);
float distance = Vector3.Distance(playerPos,planePos);
if (distance <= 1)
{
// do something
}
it's working for a simple things, like a not resized plane, a plane it's exactly what i'm using... as showing in the following image a want a way to understand when player is going off that a specific plane, like colliders, i'll regulate also the y position of the character by the plane position so you can understand that it should be more accurate as possible.
there is a way to create somithing like colliders?
Is there a reason you're avoiding the builtin collision system or is this just an educational interest?
Answer by Vonni · Oct 05, 2018 at 03:44 PM
Is it a grid? If not, are the areas always rectangular/square? Are they always aligned?
You could make use of mesh.bounds, convert that to world space. Then test if your char.position is within that space.
If you went with colliders, it could be triggers for areas. Or normal colliders and detect what you are standing on.
is a racetrack builded as in the showing in this picture
with the method that i wrote in the top i'm able to detect the distance from the next plane by checking only the z axis, but it will change for some other plane as you can see from the picture, so i'm looking for something more powerfull.
i'm trying to do what you told me, but i can't see the box around the object, i'm doing wrong something?
meshfilterArray = gameObject.GetComponentsInChildren<$$anonymous$$eshFilter>();
meshArray = new $$anonymous$$esh[meshfilterArray.Length];
boundsArray = new Bounds[meshfilterArray.Length];
for (int i = 0; i < meshfilterArray.Length; i++)
{
meshArray[i] = meshfilterArray[i].mesh;
boundsArray[i] = meshfilterArray[i].mesh.bounds;
}
rendererArray = gameObject.GetComponentsInChildren<Renderer>();
for (int i = 0; i < meshfilterArray.Length; i++)
{
boundsArray[i] = rendererArray[i].bounds;
}
Bounds totalBound = new Bounds();
for (int i = 0; i < boundsArray.Length; i++)
{
Bounds bound = boundsArray[i];
totalBound.Encapsulate(bound);
}
Racetrack, hmm. That's more fast pace than I imagined. $$anonymous$$aybe my suggestion is not the best here. It's hard to suggest when I don't know the whole story. Why not just raycast down from player/vehicle and see what plane you hit?
Your answer
Follow this Question
Related Questions
brick does not detect collision although ball does 2 Answers
Detecting Collision between Charctor controller and Box Collider 2 Answers
Multiple Colliders On A Single Object Detecting Each Collider In OnTriggerEnter() 1 Answer
Basic collision not working - c# 1 Answer
Spawning 3D Objects according to Data at JSON Matrix 0 Answers