Skip to main content
corrected grammer
Source Link
plainerman
  • 331
  • 2
  • 10

If it should only hitwork with left, up, right, and down usinguse Raycasts.! Your code will look like this

public float[] CheckCollisions() {
    Raycast hit;
    float[] collisions = new float[4];
    if (Physics.Raycast(transform.position, transform.Vector3.Up, 100.0f, out hit))
        collisions[0] = hit.transform.position - transform.position;
    else
        collisions[0] = Float.NaN;
    //other directions
    return collisions;
}

It isn't the most beautiful way - make a Vector3 array with all directions you wanna check and then iterate through, and check current Vector for hit.

Sorry for any mistakes, wrote this with my cellphone.

If it should only hit with left, up, right, and down using Raycasts. Your code will look like this

public float[] CheckCollisions() {
    Raycast hit;
    float[] collisions = new float[4];
    if (Physics.Raycast(transform.position, transform.Vector3.Up, 100.0f, out hit))
        collisions[0] = hit.transform.position - transform.position;
    else
        collisions[0] = Float.NaN;
    //other directions
    return collisions;
}

It isn't the most beautiful way - make a Vector3 array with all directions you wanna check and then iterate through, and check current Vector for hit.

Sorry for any mistakes, wrote this with my cellphone.

If it should only work with left, up, right, and down use Raycasts! Your code will look like this

public float[] CheckCollisions() {
    Raycast hit;
    float[] collisions = new float[4];
    if (Physics.Raycast(transform.position, transform.Vector3.Up, 100.0f, out hit))
        collisions[0] = hit.transform.position - transform.position;
    else
        collisions[0] = Float.NaN;
    //other directions
    return collisions;
}

It isn't the most beautiful way - make a Vector3 array with all directions you wanna check and then iterate through, and check current Vector for hit.

Sorry for any mistakes, wrote this with my cellphone.

If it should only hit with left,up up,right right,down use and down using Raycasts.Your Your code will look lile thatlike this

public float[] CheckCollisions() {
    Raycast hit;
    float[] collisions = new float[4];
    if (Physics.Raycast(transform.position, transform.Vector3.Up, 100.0f, out hit))
        collsisions[0]collisions[0] = hit.transform.position - transform.position;
    else
        collsisions[0]collisions[0] = Float.NaN;
    //other directions
    return collissions;collisions;
}

ThisIt isn't the most beautiful way, - make a Vector3 array with all directions you wanna check and then iterate through (and, and check current Vector for hit).

Sorry for any mistakes, wrote this with my cellphone.

If it should only hit with left,up,right,down use Raycasts.Your code will look lile that

public float[] CheckCollisions() {
    Raycast hit;
    float[] collisions = new float[4];
    if (Physics.Raycast(transform.position, transform.Vector3.Up, 100.0f, out hit))
        collsisions[0] = hit.transform.position - transform.position;
    else
        collsisions[0] = Float.NaN;
    //other directions
    return collissions;
}

This isn't the most beautiful way, make a Vector3 array with all directions you wanna check and then iterate through (and check current Vector for hit)

Sorry for mistakes, wrote this with cellphone.

If it should only hit with left, up, right, and down using Raycasts. Your code will look like this

public float[] CheckCollisions() {
    Raycast hit;
    float[] collisions = new float[4];
    if (Physics.Raycast(transform.position, transform.Vector3.Up, 100.0f, out hit))
        collisions[0] = hit.transform.position - transform.position;
    else
        collisions[0] = Float.NaN;
    //other directions
    return collisions;
}

It isn't the most beautiful way - make a Vector3 array with all directions you wanna check and then iterate through, and check current Vector for hit.

Sorry for any mistakes, wrote this with my cellphone.

Source Link
plainerman
  • 331
  • 2
  • 10

If it should only hit with left,up,right,down use Raycasts.Your code will look lile that

public float[] CheckCollisions() {
    Raycast hit;
    float[] collisions = new float[4];
    if (Physics.Raycast(transform.position, transform.Vector3.Up, 100.0f, out hit))
        collsisions[0] = hit.transform.position - transform.position;
    else
        collsisions[0] = Float.NaN;
    //other directions
    return collissions;
}

This isn't the most beautiful way, make a Vector3 array with all directions you wanna check and then iterate through (and check current Vector for hit)

Sorry for mistakes, wrote this with cellphone.