youvsvirus / youvsvirus-unity

Unity version of the you vs virus game.
GNU General Public License v3.0
1 stars 1 forks source link

Add a new prefab nonSpawnable space #104

Closed holke closed 4 years ago

holke commented 4 years ago

This prefab can be equipped with circle colliders that define space in which no NPC should spawn. The RandomGrid and CreatePop scripts check their coordinates and if they are in non-spawnable space regenerate them.

Please check this out. Would love to hear your feedback on this and if this is a viable solution. Unfortunately it is not very efficient if the area is large due to the way the grid coordinates are currently computed.

maccxs commented 4 years ago

Hi, seems to work fine. But I do not really yet understand what you are doing here. You create a Game Object with a circle collider and put it somewhere nothing should spawn. What does ''' foreach (CircleCollider2D collider in colliders2D) { ''' this exactly do? Don't I have only one circle collider on each clone of the prefab? Would this affect other circle colliders in the game? Why do we use colliders at all? If we go into the coordinate business and there already is an object, I could get this objects coordinates or the edges of its transform or whatever to check that this coordinate is not chosen for spawning?

Ok, so maybe this is about not worrying about coords and simply drawing circles around objects where nothing can spawn? I think I get this. But still don't understand the foreach. If I have multiple clones of the prefab each still only has one attached collider.

Still, it seems to be an easy method to get this done, I just need some more explanation.

holke commented 4 years ago

Okay, some more explanation:

The idea is to have only ONE nonspawnablespace object per scene which define ALL space where nothing should spawn via multiple colliders. So you add on object and add as many colliders to it as you want such that they cover all space in which nothing should spawn. The loop that you quote is just the loop over all these colliders.

Why circle colliders? It turns out that unity does not have an „isInsideObject“ function. So we are left with checking the coordinates by hand and circles are just the most practical to check. And I think we do not need such fine control of the nonspawnablespace that we need other forms as well.

It would not affect other colliders in the game.

Also keep in mind that this is not „non walkable space“, which can still easily be set with object colliders.

Does this clarify your questions?

holke commented 4 years ago

Also if you turn your gizmo view on, you can see the colliders even when you don’t select them, thus providing you with a nice and quick view of the non spawnable space in the editor. Kind of like a UI ;)

maccxs commented 4 years ago

Yes, thank you :-) I like the solution.

holke commented 4 years ago

Did i get everything or do i need to change more?

maccxs commented 4 years ago

Okay, some more explanation:

The idea is to have only ONE nonspawnablespace object per scene which define ALL space where nothing should spawn via multiple colliders. So you add on object and add as many colliders to it as you want such that they cover all space in which nothing should spawn. The loop that you quote is just the loop over all these colliders.

Why circle colliders? It turns out that unity does not have an „isInsideObject“ function. So we are left with checking the coordinates by hand and circles are just the most practical to check. And I think we do not need such fine control of the nonspawnablespace that we need other forms as well.

It would not affect other colliders in the game.

Also keep in mind that this is not „non walkable space“, which can still easily be set with object colliders.

Does this clarify your questions?

So if I want more non-spawnable space I add more colliders to that object? Sorry, I feel quite stupid to asks that again. When I do this, I can no longer place the colliders independently of each other by drag and drop. Or should I make child colliders? But this does not work....

maccxs commented 4 years ago

Have to stop for today.

holke commented 4 years ago

So if I want more non-spawnable space I add more colliders to that object? Sorry, I feel quite stupid to asks that again. When I do this, I can no longer place the colliders independently of each other by drag and drop. Or should I make child colliders? But this does not work....

Ähhhhh, yes you add more colliders (no child colliders) and actually the drag and drop doesnt work for me even with one collider. I allways use the x,y sliders to adjust the position.

maccxs commented 4 years ago

@holke : Merge master and then I will merge this pull request

maccxs commented 4 years ago

Got a small furter idea for layer naming. Maybeisntead of collidesWithXbutNotY just name it withXnotY which is shorter and also understandable if we make this a convention?

holke commented 4 years ago

Merged with master

holke commented 4 years ago

Got a small furter idea for layer naming. Maybeisntead of collidesWithXbutNotY just name it withXnotY which is shorter and also understandable if we make this a convention?

Yes, this would clarify the names. Should be an own issue i think.

maccxs commented 4 years ago

Maybe introduce a further routine .GenerateRandomCoords that does not need the spawanable object? We won't need this in every level. HAve you made sure that all other levels, e.g. sandbox are working? Or do we want to have this in every scene? More a question of: What is your opinion? Not fix this.

holke commented 4 years ago

you are right, i need to check this.