Field of Vision obstructed when colliding w/ a gameobject
This image explains what I want in a nutshell for a unit in an RTS
Essentially, the Field of Vision gameobject in the image would have a script attached to it that morphs shape when it runs into a new gameobject.
I have no idea how to code this script. It emulates what a person's field of vision would look like if he looked at a wall. He cannot see through the wall so his field of vision shrinks slightly.
Here is what the field of vision would look like with no obstruction.
@MJMC brought up a good point so I must add that: the player can see the other side of obstructing gameobject, but the gameobject cannot. Think of a unit from Command and Conquer or Starcraft. the field of view gameobject must be able to detect collisions.
Tutorial link : https://www.youtube.com/watch?v=rQG9aUWarwE Note: I think the title for this question is horrible! Suggestions welcome :)
Answer by isteffy · May 17, 2016 at 06:59 AM
@SebastianLague This two-part tutorial is above and beyond what I wanted. No cameras needed, only some slick trigonometry which Sebastian does for you.
Part 1(basics) https://www.youtube.com/watch?v=rQG9aUWarwE∈dex=4&list=PLrWUz1h2nDpPdne1qzCt6Je1BUNWh8Ckm
Part 2 (more making the field of vision visible) https://www.youtube.com/watch?v=rQG9aUWarwE∈dex=4&list=PLrWUz1h2nDpPdne1qzCt6Je1BUNWh8Ckm
Answer by Nazirzadeh · May 13, 2016 at 06:30 PM
Of course it is horrible :)
Do you want to see the other side of the wall? If yes you can add a second camera a little bit ahead of your main camera and deactivate it, after reaching to the wall you can deactivate first camera and activate second one.
The game is a top down RTS, so you as the player can see the other side of the wall, however the gameobject with the field of view cannot see another gameobject hiding behind that wall. The field of view is a gameobject. Could I use the view of the camera and convert it into an actual gameobject that can detect collisions?
Also thanks for the honesty :) Do you have a better suggestion?
you can use raycast to notice if an object is in the field of view.
http://forum.unity3d.com/threads/raycasting-a-cone-ins$$anonymous$$d-of-single-ray.39426/
Okay so in order for this to work, I would need to figure out a way to make the camera's field of vision something that can be literally seen by the player.
To change all of my field of views from a gameobject to a camera that casts visible field of vision that uses raycasts will take some time, so I will wait a little bit to see if someone can answer my question using purely colliding gameobjects.
Your answer
Follow this Question
Related Questions
Particle Collision causes Explosion?,Explosion on particle contact? 0 Answers
Make a Particle System play when Player gets destroyed 0 Answers
Add collision to mesh 0 Answers
Disable input while falling? 2 Answers