Search Unity

Help with detecting the width of an object

Discussion in 'Scripting' started by Aidenjl, Feb 8, 2015.

  1. Aidenjl

    Aidenjl

    Joined:
    Jan 5, 2014
    Posts:
    81
    Hello!

    So, in Unity I've been trying to make some semi-realistic bullet mechanics. As it goes I've been having a few problems to say the least on trying to detect the distance the bullet travels through an object. Here's a picture example:
    Problem.png
    So, the method I was trying to use was by having the bullet do a raycast all both forwards and backwards, the hit results were then logged into arrays, I then used Vector3.Distance to measure the distance between the corresponding hits. However this did work when only passing through one object but when it passed through more than one I encountered some strange errors that I couldn't figure out the cause of.

    I was just wondering if anyone could point me in a different direction/approach on how they would do it, any help would be much appreciated.

    Thanks - Aiden Leeming :)
     
  2. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    If you are doing this for the purpose of deciding if the bullets penetrates or not. Although not as accurate I would just decide via with width of the bounding box. Not fully accurate but should be close enough for game play purposes. This is the way it is done in counter strike.

    Get the bounding box info from the hit, and decide which dimension you want to use based on the raycasts direction.