Porting car tutorial to iPhone

Hello,

I plan to buy the addon IOS for Unity, but before I’d like to know if is it easy to port the project of car tutorial (link) to the platform iPhone ? Is there a lot of modifications to do ?

I never tried the one you refer to, but found this one helpful and that worked on iPhone (i don´t remember if i had to make some adjustments in code, though)

… And i had a look at the unity tutorial, well, you sure can get that to run but say goodbye to the lanscape. That looks like a unity terrain with trees and such, which is not supported on iPhone. I guess you need to model the terrain as lowpoly yourself. Same with the trees. And the car model might not be lowpoly enough.

marjan: How did you convert it for iphone? What about controls? I’m trying to make it controlable with iphone accelerometer and add GUITexture for gas and brake, but with no luck. :frowning: Any idea?

Hi, well i didn´t say i converted it. Until now.

This is what i did to get it to run:

  • In code i only had to adjust two lines everything else was just fine. that was in skiidmarks.js and i had to change

GetComponent(MeshFilter).mesh = new Mesh();

to

var myMeshFilter:MeshFilter = GetComponent(MeshFilter);	
	if(myMeshFilter.mesh == null)
		myMeshFilter.mesh = new Mesh();
  • As i said, this tutorial uses terrain and other stuff that is anyways not supported on iPhone. I needed to take the terrain and water out and then go through the code and take out everything that refers to it.
  • I think after that i was ablle to build
  • Game loaded on the device but crashed because of some shader. Unfortunatly i could figure find which one. So i just exchanged most shaders to diffuse and deleted and/or switched of most geometry.
  • so basically there is not much left besides the street and the car now.

Now it starts and runs at 7 - 15 FPS. Really slow.
Furthermore it needs very long to start up, because of all the textures. Here it only runs when iPad is connected to my computer and started by xcode. To make it run without one needs to delete a lot of textures or scale them down.

I did not make any effort to optimise it, makes no sense. Best is to delete everything except the car and make your own geometry and textures.

AS for controls, i only scripted in some really shitty control to at least be able to do something on the device. Used acceleration for it. You need to put one finger on the screen and then tilt the device.
This turned out really really bad but you can easily put your own control in there.

that part is ion car.js which i changed to:

function GetInput()
{
	
	
		if (Input.touchCount > 0) {
			var t1:Touch  = Input.GetTouch(0);
		
			throttle = Input.acceleration.x;
			if(t1.phase == TouchPhase.Ended || t1.phase == TouchPhase.Canceled ) {
				throttle = -1;
			}
		} else {
			throttle = Input.GetAxis("Vertical");
			steer = Input.GetAxis("Horizontal");
		
		}
		
		steer = -Input.acceleration.y;
		
	if(throttle < 0.0)
		brakeLights.SetFloat("_Intensity", Mathf.Abs(throttle));
	else
		brakeLights.SetFloat("_Intensity", 0.0);
	
	CheckHandbrake();
}

Again, that works reaaaally bad, but at least you can drive a bit.

So, to make this good everybody is welcome to download my project, delete all the geometry an make new lowerpoly, less textured stuff.

You can download the project from my server here.

I set the player up for iPad, don´t forget to put in your own developer name. I guess this requires unity 3 and export to opengl es 2 as some shaders use that. I didn´t try the other way.
The physics itself and the scripts should work everywhere. So if you cannot get this to run with your version of unity, just go ahead and delete more and more and change the shaders to something like diffuse. That should do the trick.

I got a car working on iOS, using wheel collider physics, but the physics update is reeeaaally slooow, regardless of what you do with the graphics. Unless you are targetting new H/W only, its not worth it. Suggest writing your own fake physics if it needs to run fast.

If it needs to run on old hw you don’t use physics simulations at all but “arcade that looks somewhere believable” :wink:
Its well known that the pre 3GS ones are rather limited on cpu especially cause the cpu has to be shared with AI but especially drawcalls too which are rather limited and the more you push on physics and ai, the less drawcalls you have (you can go up to 4 cars in total on pre 3gs but beyond it you will pretty definitely hit walls due to the lack of cpu to feed all 3 cpu heavy areas enough cpu time)

also try reducing your fixed update settings to 30fps instead of 60
or in the build settings, reduce the accelerometer interval…
change all the shaders to use unes from the /mobile/ shader folder
These changes will give you a decent performance boost.

Hi All I was using this frame work for a driving setup for iphone (work ok on iphone 4) so was happy with it.

However with the new Unity 3.4 the car.js script has some error (just defining variable types) however I am still getting an error

I changed these values

var normPower : float;
var accelerationTimer : float;
var wheel : Collider;

not sure what to define the array as

private var wheels : Wheel[ ]; ?

has anyone got this script working in 3.4.

Or has anyone come across a better (basic) driving frame work for iphone ?

I think you might have more luck with edy’s on the appstore. It’s relatively inexpensive and I use it, its just a couple of scripts. I think that var wheels might well be of type GameObject if memory serves me.

cheers hippo yer I got Edys car pack (its mint) but dont think it works for mobile?