- Home /
Question by
Relan42 · Aug 16, 2021 at 02:49 AM ·
scripting problemhit.pointspherecastall
Getting the points from a SphereCastAll
I am trying to make an object be repelled from it's environment when I press a certain key. I'm trying to do this by creating a spherecastAll and then getting all the points where the shpere cast collides with something, the add an explosion force to the player based on each point. The problem is that for some reason the sphereCast doesn't return any values.
if (Input.GetKey(KeyCode.Mouse2))
{
RaycastHit[] hits;
hits = Physics.SphereCastAll(player.position, 20, Vector3.zero, AttractableLayerMask);
RepulsionPoints.Clear();
for (int i = 0; i < hits.Length; i++)
{
RepulsionPoints.Add(hits[i].point);
player.AddExplosionForce(RepulsionForce,RepulsionPoints[i], RepulsionRadius);
}
}
I also tried to do the same but with a raycastAll just to see if it had something to do with the fact that I'm working with arrays or something like that, but it works perfectly with a raycastAll. This means that the problem is with the sphereCastAll.
if (Input.GetKey(KeyCode.Mouse2))
{
RaycastHit[] hits;
hits = Physics.RaycastAll(player.position, camera.forward, AttractableLayerMask);
RepulsionPoints.Clear();
for (int i = 0; i < hits.Length; i++)
{
RepulsionPoints.Add(hits[i].point);
player.AddExplosionForce(RepulsionForce,RepulsionPoints[i], RepulsionRadius);
}
}
Does anyone know what am I doing wrong or how to get the same results through a different method?
Comment
Your answer
