Do I need Rigid2DBody if I don't plan to use physics?
Disclaimer - I'm completely new to Unity - went through the basic 2D tutorial and have read topics on these forums and in docs but that's about it.
I'm working on a simple ant colony simulation (a toy ant colony optimization algorithm) with a small fixed game board, food and obstacles placed randomly, and the ants controlled completely by the algorithms (no player controls). I don't plan to use any physics at all but I do want the ants to stay within the board and they need to be aware of when they 'collide' with obstacles or food (note that I don't want them bouncing off the obstacles and I might want them to actually sit directly on top of the food sprites). I'm also planning on moving the ants using their position instead of applying 2d forces (is that a bad idea?)
Do I use a 2D Rigid Body and colliders on the ants, food, obstacles, and 4 rectangles bounding the game board sprite? And then I set everything to Is Kinematic = true to prevent physics and use triggers?
Extra question - does it make sense to have an otherwise empty game object 'GameController' with the only component a script that produces ants, randomly places food and obstacles? (From my reading it seems like that's how it's done but want to make sure)
Answer by thereisnotrying · Apr 19, 2016 at 08:11 AM
If you want to use the triggers to detect if an ant sits on top of the food than you need rigidbodies. Regarding movement i would suggest applying forces. You can searchengine things like how to move towards a point.
GameController makes perfect sense.
Answer by Immanuel-Scholz · Apr 19, 2016 at 08:20 AM
Using a kinematic Rigidbody together with triggers is a very sensible way of scripting. A lot of games do not utilize non-trigger colliders - there is nothing wrong with that. Also, moving rigidbodies via transform.position (and not via the rigidbody) works fine.
If you only occasionally need to test for overlapping of objects, you can also use all the Physics2D.Overlap*
functions and don't need any rigidbodies at all (be sure to check "Queries Hit Triggers" in Physics2D settings of your project or else the trigger areas will not be returned).
As for the second question: Yes, it is totally normal and very common to use GameController - like objects with only few or one component and where the transform position is irrelevant. Even the build-in systems in Unity use this technique, i.e. if you create any UI component, Unity will automatically add an "EventSystem" game object which is some kind of controller-object for all your UI events..
Your answer
Follow this Question
Related Questions
Had to turn off gravity scale, but now player goes through walls 0 Answers
All colliders not longer working 0 Answers
A box collider 2D (Is Trigger marked) stops my player from moving which has rigidbody 2D 1 Answer
How to prevent a 2D Kinematic asset passing through a 2D Box Collider. 1 Answer
2D Physics not working correctly 1 Answer