Please suggest on collider performance issue
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Unity Community Index // iPhone Development
View previous topic :: View next topic  
Author Message
friendlydeveloper



Joined: 21 Dec 2008
Posts: 111

PostPosted: Fri Sep 18, 2009 12:06 pm    Post subject: Please suggest on collider performance issue Reply with quote
Hello,

I'm working on a racing game. Let me describe the scenery for you. The track is completely 2D and camera is looking top to bottom. Besides that there are several low poly 3D objects. So far I get about 11 draw calls and use 1.7k tris/984 verts.

Now, my problem is, that I need to detect whenever the car collides with something in the scenery and as the track is pretty complex I need quite a lot of colliders. In one scene I use about 75 of them (only box and sphere ones). Let's say the game runs ok, but not as smooth as I want. I'm on the 3GS and don't even want to think about performance on a 1st gen. iPod Touch Smile

Anyway, are there some tricks I could make use of? Maybe a different technique to detect collision or something that allows me to temporary get rid of colliders I don't need?

Any help appreciated. Thanks in advance
Back to top
View user's profile Send private message
bumba



Joined: 10 Oct 2008
Posts: 254

PostPosted: Fri Sep 18, 2009 1:00 pm    Post subject: Reply with quote
having he same collider problem. What i do:

- disable the colliders you dont need in the current cameraview (via triggers)
- using position calculations instead of colliders (eg. if position.x < 10 then...)
Back to top
View user's profile Send private message
friendlydeveloper



Joined: 21 Dec 2008
Posts: 111

PostPosted: Fri Sep 18, 2009 4:09 pm    Post subject: Reply with quote
Thanks for your answer! Using triggers sounds great. Position calculations might not work in my case, but I'll play with both ideas.
Back to top
View user's profile Send private message
friendlydeveloper



Joined: 21 Dec 2008
Posts: 111

PostPosted: Fri Sep 18, 2009 10:19 pm    Post subject: Reply with quote
Ok, I did some tests and looks like I was after the wrong thing right from the start. The colliders don't seem to be the problem. I completely removed them and tried again and still had the performance hick ups. Somewhere on this forum I found a little script to display frames per second on a GUI texture. Right after launching the game I get about 29.9-30.0 fps, which is ok. When I start driving it sometimes goes down to 27-28 and drops down to 23-24 fps when I make a turn to the right or left. Then it goes back to 29-30.

I downloaded the Jcar demo and installed it on my iPhone and even though it uses about 18 draw calls (11 on my game) and 10k verts (1.7k on my game), it runs SUPER smooth. This tells me, that the problem must be somewhere else. Jcar even uses 3 cameras. 1 for HUD elemenst and 2 for showing the scene. I use 2 cameras - 1 for the scene and one for HUD elements.

Let me share a screenshot of the scene with you:



This is the camera I use for showing the HUD elements:



And here is the main camera:



And the stats:



Do you see anything strange, that could cause my performance issues?
Thanks in advance.
Back to top
View user's profile Send private message
friendlydeveloper



Joined: 21 Dec 2008
Posts: 111

PostPosted: Fri Sep 18, 2009 10:41 pm    Post subject: Reply with quote
Ok, got some progress here. I noticed, that all my objects had cast/receive shadows turned on. Don't know if that was the problem, but after I removed it, performance got a lot better. Almost stable 30 fps now.

Was that it or did I do something else? Smile Not 100% sure, because I changed several things I can't remember now Confused
Back to top
View user's profile Send private message
Eric5h5



Joined: 19 Jul 2006
Posts: 8107

PostPosted: Sat Sep 19, 2009 2:37 am    Post subject: Reply with quote
Unity iPhone has no realtime shadows, so whether cast/receive shadows is checked or not wouldn't make any difference.

--Eric
Back to top
View user's profile Send private message Visit poster's website
JTBentley



Joined: 30 Jun 2009
Posts: 931

PostPosted: Sat Sep 19, 2009 2:44 am    Post subject: Reply with quote
Try lowering your physics iterations Smile
_________________
Bentley
Technical Director & Programmer
NextGen Reality & TheBinaryMill
Back to top
View user's profile Send private message Visit poster's website
kevinr



Joined: 24 Jul 2008
Posts: 260

PostPosted: Sat Sep 19, 2009 4:48 am    Post subject: Reply with quote
The fact that going around turns causes a significant frame drop, you might have some costly scripting operations that can be tuned.

What type of stuff do you have going on in your update methods?

_________________
Pong - Complete iPhone Game example project: http://forum.unity3d.com/viewtopic.php?t=20643&start=0&postdays=0&postorder=asc&highlight=pong
Back to top
View user's profile Send private message AIM Address
friendlydeveloper



Joined: 21 Dec 2008
Posts: 111

PostPosted: Sat Sep 19, 2009 12:28 pm    Post subject: Reply with quote
I have a main script, which handles the touch events and controls the car. I think, that cleaning up the code is a good way to start. However, I'll also study the JCar sample again, as that one works as expected an is in fact way more complex.

Thanks again for your help!
Back to top
View user's profile Send private message
friendlydeveloper



Joined: 21 Dec 2008
Posts: 111

PostPosted: Sat Sep 19, 2009 10:30 pm    Post subject: Reply with quote
Alright, let me give you an update.

After many hours of unsuccessful tweaking, I decided to create a new project and build the basic scenery from scratch.

Here is what I did:

1) Created 3 x 3 cubes and reduced their height, so they would look like planes.
2) Imported the track textures (each 512x512, .jpg format)
3) Put the track textures on the cubes.
4) Imported the JCar and JControlledCar scripts.
5) Built a very simple "car". Just a slightly stretched cube and 4 cylinders as wheels.
6) Made the main camera child of the car and rotated it, so it would look top to bottom.
7) Connected the scripts - Built the project for my iPhone.

Stats window shows 288 verts, 216 tris and 9 draw calls.

This time there are NO colliders and NO scripts I wrote myself inside the project.
Now guess what? Smile STILL no smooth movement.

I also tried an enlarged plane, that has absolutely no texture on it instead of the cubes and performance was the same.

I compared player settings, etc. to the JCar demo and they both matched.

Any clue, what could cause this? iPhone 3GS runs at 30.0 fps, iPod Touch 1st gen. at 22-28 fps, but again not smooth at all. JCar demo on the other hand runs fast as hell, has 10k+ verts, 3D models, mesh colliders, etc..

Could it be the fact, that my camera is top to bottom? As you can imagine, I ran out of ideas. Any new input appreciated. Thanks in advance.
Back to top
View user's profile Send private message
JTBentley



Joined: 30 Jun 2009
Posts: 931

PostPosted: Sat Sep 19, 2009 11:42 pm    Post subject: Reply with quote
So it really comes down to your scripting, particuarly your controls or car scripts.

Post your update loop.

If you're worried about people stealing your code, don't be. There's heaps of people on here who can script better than you or I and they give their stuff away for free Smile

_________________
Bentley
Technical Director & Programmer
NextGen Reality & TheBinaryMill
Back to top
View user's profile Send private message Visit poster's website
friendlydeveloper



Joined: 21 Dec 2008
Posts: 111

PostPosted: Sat Sep 19, 2009 11:46 pm    Post subject: Reply with quote
No, I'm not worried at all, since I use the JCar script. I wanted to make sure, that it was not my coding, that caused the problems.

However, in the meantime I got rid of all the cubes and created my own low poly planes in cinema4D. I haven't tested performance yet, but I'm down to 7 draw calls and only 14! tris/49 verts.

I'll post here as soon as I tested it.
Back to top
View user's profile Send private message
friendlydeveloper



Joined: 21 Dec 2008
Posts: 111

PostPosted: Sun Sep 20, 2009 12:11 am    Post subject: Reply with quote
Ok, tested it. Well, what can I say. It's better, but still not the same performance as JCar demo.

I'll now import the JCar model and give it a ride.
Back to top
View user's profile Send private message
friendlydeveloper



Joined: 21 Dec 2008
Posts: 111

PostPosted: Sun Sep 20, 2009 12:38 am    Post subject: Reply with quote
Done. I can now definitely say, that the hick ups only occur, when I ride on my 3 x 3 custom planes. They only have 2 polygons each, but every one of them has it's own texture.

The track basically is a 1536 x 1536 pixels image, which I sliced up in photoshop. So, I created 9 images, 512 x 512 each. Those I simply put on my custom planes, which are all static by the way. Textures are PRVTC compressed of course.

Does anyone know a technique, that allows me to keep the same track size, but with less textures? Maybe I need to think of a completely different solution for my game?
Back to top
View user's profile Send private message
kevinr



Joined: 24 Jul 2008
Posts: 260

PostPosted: Sun Sep 20, 2009 1:13 am    Post subject: Reply with quote
friendlydeveloper wrote:
Ok, tested it. Well, what can I say. It's better, but still not the same performance as JCar demo.

I'll now import the JCar model and give it a ride.


If you post your Update code, I will take a look at it. You can PM if you don't want to make it public, but I wouldn't be too concerned. I'm wondering if you are also taking advantage of some of the more basic iPhone optimizations, but looking at a chunk of code would be enough to tell.

_________________
Pong - Complete iPhone Game example project: http://forum.unity3d.com/viewtopic.php?t=20643&start=0&postdays=0&postorder=asc&highlight=pong
Back to top
View user's profile Send private message AIM Address
Post new topic   Reply to topic    Unity Community Index // iPhone Development All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum