Now, the aim is - to avoid this laser, whether it be by hiding behind a building, a car etc.
Technically - the laser is a basic primitive (a cylinder or cube) - with an Additive Particle shader that gives it the glowing/half transparent appearance.
The issue is this:
If you are hiding behind an obstacle, the laser will appear to come through this obstacle - which would negate the point of hiding.
As the laser is not a light source or physics object, the way I am assuring this does not happen is as follows:
- From the parent rotation object (the skull) cast a ray along the axis of the primitive (the laser).
- If the raycast strikes a collider, find the distance to this collider.
- Scale the laser to equal this distance.
- Assuring the laser has a starting scale of 0 along the length axis.
- Offset the laser by half of this distance.
- As primitives in unity begin with an origin directly in their centre.
- Presto, your laser is not penetrating the obstacle.
As our laser does not have to be 100% accurate, I have offset each check for boundaries (parametrically).
In a very primitive fashion....
Each listener has a counter, when the counter hits the defined check rate, it will check for a collision.
We mitigate the average damage, while still taking damage at the predefined rate.
The aim is to use this concept over all performance-detrimental tasks (collision detection, raycasting, etc), and offset the counters to assure that not all checks are occurring in one enormous spike.
A glimpse of my hilarious test scene, replete with a random cube (right), an orb flashing at 120bmp (center), a wall and the ray - white. As you can see, the ray does not penetrate the wall.
No comments:
Post a Comment