playMaker

Author Topic: How to tell if enemy is behind wall  (Read 4013 times)

wendymorrison

  • Playmaker Newbie
  • *
  • Posts: 30
How to tell if enemy is behind wall
« on: October 30, 2016, 01:38:57 AM »
Hi i have a simple wall and floor and a enemy behind the wall where the player can't see the enemy. How can you tell which object is a raycaset hit. I have it where upon holding a button and if the player can't see the enemy change to a ghost shader where the player is able to the enemy behind the wall like in last of us game. Then if you see the enemy i change to another material like a outline material. It does work but if i am behind the enemy and the raycast hits the enemy aswell as the wall it changes to the ghost shader so is there a way to say if the raycast hits the enemy change to the outline material only and if the enemy can not be seen by the player change to the ghost shader. Any help would be appreaciated and hopefully i have made this clear.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How to tell if enemy is behind wall
« Reply #1 on: October 30, 2016, 07:53:58 AM »
Hi,
I am not sure how you set this up, but raycast should hit only one object.

A common problem with a raycast from a player, is the starting position from the raycast.
When close to an object (wall) and the raycast position is against or in the wall it will not detect the wall and will cast thru the wall.

wendymorrison

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to tell if enemy is behind wall
« Reply #2 on: October 30, 2016, 06:03:50 PM »
Hi,
I am not sure how you set this up, but raycast should hit only one object.

A common problem with a raycast from a player, is the starting position from the raycast.
When close to an object (wall) and the raycast position is against or in the wall it will not detect the wall and will cast thru the wall.

yeah it seems to hit both. It actually depends on where the player is. I have also added a compare tag but it just does the same thing.

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: How to tell if enemy is behind wall
« Reply #3 on: October 30, 2016, 06:16:29 PM »
You could try the FOV actions as a starting point...

wendymorrison

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to tell if enemy is behind wall
« Reply #4 on: October 30, 2016, 06:37:48 PM »
You could try the FOV actions as a starting point...
Sorry that won't help. I have done everything else its just the raycast hits more than one thing. But i was actually thinking how can you do this without a raycast because i actually need it to work without the ray hitting the enemy but still work if player see the enemy and if player can't see the enemy because of a obstacle in the way it changes material.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How to tell if enemy is behind wall
« Reply #5 on: October 30, 2016, 08:15:18 PM »
Hi,
yeah it seems to hit both. It actually depends on where the player is. I have also added a compare tag but it just does the same thing.

Can you make a video, when it happens and when not in the scene view and maybe show the fsms/states/actions you are using.

wendymorrison

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to tell if enemy is behind wall
« Reply #6 on: October 30, 2016, 08:33:44 PM »
Hi,
yeah it seems to hit both. It actually depends on where the player is. I have also added a compare tag but it just does the same thing.
Sorry i can make a video but i haven't got a youtube account yet. I have decided to go with a simpler version.
I do a default state with a GET BUTTON DOWN action, i use m in the project settings input then i SET MATERIAL with the normal materal thats on the enemy. I had to do this 4 times since i am using the mixamo cop zombie. I also use a finish transition to the next state. The next state i also have a finish transition back to the default state. In that state I use GET BUTTON DOWN with the same button m. I do this so i have to hold m down. I then do SET MATERIAL 4 times again but only i use a shader that the player can see through the wall and also looks ok when zombie is visible. That is the simplest version only. In the more difficult version i actually wanted the shaders better and i just wanted to determine if the zombie was behind the wall and if so do a shader that can be seen through a wall but if the zombie is visible to the player then just do a normal outline shader. But if the player can only see half the zombie and the other half i would have maybe determine both shaders. If any one could maybe give me a tutorial to do a similar hold button down like in the last of us game it would be great. Otherwise i might have to stick to the simplest version.

Can you make a video, when it happens and when not in the scene view and maybe show the fsms/states/actions you are using.

wendymorrison

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to tell if enemy is behind wall
« Reply #7 on: October 30, 2016, 09:22:46 PM »
Sorry for another post just realized i needed a capsule collider on the zombie and now it detects if it a obstacle or the enemy but still can't work out if the raycast hits a obstacle when enemy is visible what to do next though.

wendymorrison

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to tell if enemy is behind wall
« Reply #8 on: October 30, 2016, 10:09:38 PM »
Hi just decided to show you all screenshots. I have the FSM on the fpscontroller. Sorry i only can post 4.

wendymorrison

  • Playmaker Newbie
  • *
  • Posts: 30
Re: How to tell if enemy is behind wall
« Reply #9 on: October 30, 2016, 10:11:18 PM »
Here is the other screen shots. Hopefully these help you to understand what i am trying to do.