- Home /
I got a problem with using the OverlapseSphere() method inside a different PhysicsScene
I am firing a projectile, on hitting an object it should explode and dmg all the objects within a radius. For this I am using a separate PhysicsScene. The physics within this scene are simulated each update. So when the projectile collides with a player or the map it will trigger the code underneath. I have tested what the scene is of the object it hits and it is the serverScene. But I never get a result from the OverlapsSphere. (another thing.. Why does this use a buffer for which I need to instantiate an array with a fixed size instead of returning the collision[]) I hope someone can help me!
private void OnCollisionEnter(Collision collision)
{
Collider[] hitColliders = new Collider[5];
Debug.Log(collision.gameObject.scene.name);
int test = WorldController.serverScene.GetPhysicsScene().OverlapSphere(transform.position, 1000, hitColliders, default, default);
Debug.Log(test.ToString());
int i = 0;
while (i < hitColliders.Length)
{
if (hitColliders[i] == null)
{
break;
}
Debug.Log("Collide + " + hitColliders[i].gameObject.name);
ReferenceScript script = hitColliders[i].GetComponent<ReferenceScript>();
if (script != null)
{
script.controller.Damage(50);
}
i++;
}
networkObject.Destroy();
}
Answer by lgarczyn · Oct 14, 2019 at 06:41 PM
default
here isn't the function default value, it's the default value of the type of layerMask
. And a layerMask is just an int. And the default value of an int is 0. And a layerMask of value 0 means "ignore every layers".
![alt text][1]
Isn't layer$$anonymous$$ask 0 just the default mask that is assigned to every object on creation standard? [1]: /storage/temp/147429-2019-10-14-20-52-12.png
Nope, but great question!
> If the layer$$anonymous$$ask = 0, we will never find any collisions with the ray.
Layer 0 is different than layer$$anonymous$$ask 0. The layer$$anonymous$$ask to get the first layer would have the first bit set to 1, and would therefore be 1. The default parameter is just a layer$$anonymous$$ask with everything but the ignoreRaycasts layer.
Your answer
Follow this Question
Related Questions
Restrict two objects from getting too close. 1 Answer
I want my Player to have collision physics 1 Answer
Unity's Breakout Tutorial Ball Issue. 1 Answer
Surface with hole and Raycast - Which collider 1 Answer
How to Physics.CheckCylinder? 2 Answers