how make a wall to protect enemy from raycast

hi .
y try on google, and unity answers, but not working yet.
please, is there a simple code to make raycast do not pass through the walls andkill enemies ?

in other words, i have asoldier enemy hiding on treesand walls, but rycast always hit and kill.
please , how can i make , or compare tag, when raycast hit the wall,dontkill the enemy ?

please need help on this.
i apreciatte so much any help.

.2344727--158646--enemy raycast.jpg

note:
dontput my raycast code i am using because is very simple and basic raycast code.

does the tree/wall have a collider?

1 Like

yes Sr.
in fact … use 2 more invisible collide … to protect enemy. … like a trigger and not.
but not working yet.
please help

My initial thought is that maybe your obstacles are on a different layer, but you want to include that layer when you do your targeting raycast.

ok … i madea new leyer, and anemies, and walls , go on sameleyer … some times working, and some times not.
i will try more with anothers collides …

The code is relevant, even if it is very simple. Like that we get a far better idea and you can get better help…

thanks.

    var EffectsObject1: GameObject;
    var emitter : ParticleEmitter;
    var TheDamage = 100;

function Update () {

    var hit : RaycastHit ;
    var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));

    if (Input.GetMouseButtonDown(0))
    {
        GetComponent.<AudioSource>().Play();// shoot sound       
        emitter.GetComponent(ParticleEmitter).emit = true; //hit wall particles sys
       
        if (Physics.Raycast (ray,hit,100))   
        {   
            // small particles on hit.point
            var particleClone = Instantiate (EffectsObject1, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(particleClone.gameObject, 1);
           
            hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
            Debug.Log (hit.collider.name);               
        }
    }
            else
        {
        emitter.GetComponent(ParticleEmitter).emit = false;
        }   
}

thanks for any help /
here is the video…
the wall is working, and protect now the enemy, but
when the enemy is very close to the wall… there is no more protection

why cloud be ?

thanks.
here the video.

You’ll have to show your latest code for that. The video shows the problem, but - so far as I can tell - it doesn’t give the cause.

i thinks i solve it …
there is a script to doble thehit damage… and now i cancel.
thanks a lot.

It sounds like you’re on your way then. Good luck! :slight_smile: