The object destruction (and implied creation), sendmessage, and tag comparison are all killers. Get rid of those if you can.
Don’t destroy objects at all, put them in a pool and reuse them.
Instead of tag comparisons, use layer based collisions.
Instead of sendmessage, do GetComponent and a direct method call.
Also reduce physics resolution and iteration as much as possible.
At least, that’s what I did for Oh Shoot! and it can handle a reasonable bullet hell on 1st Gen devices.
You say you don’t need physics? Does that mean you’re moving all rigidbodies yourself? Using optimized physics for that is probably faster and easier to tweak.
Thank you for your answer. I will try to remove the instantiate, destroy and compare commands.
I do not need physics at all because the opponent plane, when instantiated, will look and fly directly to the player with always the same speed. yes, I move the rigidbodys by myself (they will always get a new transform.position, transform.rotation).
Is it possible to check collisions between colliders if all objects do not have a rigidbody?
Quite strange. I have around 60 MeshColliders on my scene plus some other primitive colliders, and my game runs at 30 FPS. Also I’m instantiating objects every 1-2 seconds, but I don’t have drastical performance drops…
I would just put bullets or anything that is created/destroyed in a fairly timely manner in an object pool (just deactivate when you are not using it, and activate it when you need to use it).
The online GetComponent documentation explains it pretty well. Just do other.GetComponent(MyScript).DoSomething(), or other.GetComponent().DoSomething() if you would switch to C#.
The catch is that you need to be sure that the other object has the MyScript component before you call the method. You could first store the component in a variable and check whether it’s null, but that means you could be doing pointless component lookups.
If you make sure all your potentially colliding objects have MyScript attached (or a component that extends MyScript) then you can safely call the method without checking. Combine this with layer based collisions and you can be 100% sure which components the other has.
Checked out the web version. To me, it looks like all moving stuff in Retro Pilot can be driven by physics without much trouble. A 15 fps update with interpolation for enemy planes, bullets, and clouds might work just fine. But it doesn’t look like such optimization is really needed with so few planes and bullets moving around, if you use the other tricks.
Yesterday I have put all Objects which should be destroyed into a pool so I did not need to destroy / instantiate them every time. The framerate did not become much better.
Tomorrow I will try to use different layers to get less collisions and to remove the sendmessage-commands.
this is the slow way of using sendmessage. use version for a speed gain. but I still don’t see how this would slow it down as its only called in onCollisionEnter, so its not very frequent.
One thing to bear in mind.
The physics might not be slow.
Physics are done on the CPU.
Your other scripts could be taxing the cpu so much, that physics seems slow and gets faster when you remove colliders.
On iphone, use the profiler in xcode. It will tell you where the issue is. Enable it in appcontroller.mm
My suspicion is that physx will only take up about 1-2% and its your scripts that the big issue.
I played your game and it is very simplistic. The cause of the slowdown (true cause) must be profiled. You can do this in appcontroller.mm. Also set kFPS to 60 and accelelerometer to 1.0.
Question.
In unity player build settings have you put “fast but no exceptions” because otherwise you game will run too slow with error checking.
I have enabled “fast but no exceptions”, the kFPS is set to 60 and the acceleroeter is set to 0.0.
On my PC I have around 3000 fps - and my PC is over 4 years old…
If I delete all rigidbodies and all colliders the game is still very slow. So I think you are right and the code will be the reason for slowing down the game. Sadly I have no idea at the moment what it could be. The code is not very long and I think I have not made such a big bug…
Please what do you mean with “use version for a speed gain”.