- Home /
(Light enabled colliders) given a surface, how to make a collider such that only the portions of the surface in contact with a light source are activated?(Game example included)
I'm trying to create an effect I saw in this game Play Here or See GIF here
where you have a platform for a player to walk on. but at any given time, only the portion of that platform that is in contact with a light source(which can be multiple, static or dynamic) is walkable,whereas the rest, which also happens to be invisible, is not.
what I was able to achieve so far is GIF here simply by :
1- using SphereCast (around my light object , light radius) get floor I'm contact with
2-adjust the position of a pre built Collider such that it's position.y & z = floor.position.y & z and it's position.x = light.postion.x
3-adjust the size of the Collider such that the width = sqrt(radius^2 - y difference^2) // circle equation
there are multiple issues with my approach however:
1- if the player walks towards the edge of the floor, the collider move past it i.e protrudes from the side 2-if the floor was Vertical, a wall, I need to adjust the equation such that the height is = = sqrt(radius^2 - x difference^2) 3-doesn't work for tilted surfaces
do you guys have any idea on how to do this effect?
code here
public LayerMask floorMask;
public float radius = 2;
public GameObject fCollider;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Physics.CheckSphere(transform.position, radius, floorMask))
{
Collider[] floors = Physics.OverlapSphere(transform.position, radius, floorMask);
fCollider.SetActive(true);
Vector3 temp = floors[0].transform.position;
temp.x = transform.position.x;
fCollider.transform.position = temp;
Vector3 tempSize = fCollider.transform.localScale;
tempSize.x = Mathf.Sqrt(Mathf.Pow(radius, 2) - Mathf.Pow(transform.position.y - tempSize.y, 2));
fCollider.transform.localScale = tempSize;
}
else {
fCollider.SetActive(false);
}