Showing posts with label Raycasting. Show all posts
Showing posts with label Raycasting. Show all posts

Friday, February 14, 2014

Update 30: Line of Sight

I've managed to implement a simple line of sight mechanic with ray casting. If my character can't see an enemy - because they are behind another object and therefore, not in 'line of sight' of my character, I hide the mesh renderer on the object, effectively making it invisible. 




The great part about this solution is that the enemy character is still there and it's AI is still running. When the enemy character comes back into view again, I just enable the mesh renderer. Every time a character moves, I ray cast between each character and enemy to see if they are visible and then hide and show the enemy character depending on if they are in the line of sight of my player.

Here is a sample where I can't see the enemy (although, because I haven't yet replaced the UI of the enemy characters, you can see their health bars - this will be fixed later):




And here, after I move around the obstacle, I can see the enemy character again.



Friday, March 15, 2013

Update 9: Destructible Terrain

As I worked through the shooting mechanics and really got ray casting to work properly, I suddenly found that I couldn't shoot my enemies. I was initially perplexed, but then quickly realized that everything was working perfectly: the shot was hitting the cover (wall) in front of the target. 

It was time to implement destructible terrain.  


Part 1: I aim an the enemy on the far right. He happens to be under cover, so my shot hits the wall in front of him.



Part 2: The wall currently only has a HP of 1, and my laser does 1 HP of damage, so the wall is destroyed. With the wall gone, the enemy is exposed and can be hit easily. In the current prototype, characters have 3 HP, so just 3 more hits from the laser and he will be dead!