- Home /
iPad: accelerator tilt breaks collider
I'm working on designing an iPad game in which the player tilts the ipad in order to move around the map.
I found this: http://unity3d.com/support/documentation/Manual/Input.html
It does EXACTLY what I needed.
Now, here is the problem.
When ever I this script I get an issue where the collider's are ignored. Using a very basic example, I made a sphere with a sphere collider and attached a padtilt.js to it. Then I made some walls (with colliders) and a plane (with colliders).
The sphere will stay on the plane, but when I get to a wall it completely ignores and passes through.
I've added rigidbody to the walls and that works, but of course the walls bounce all around. I can add the rigidbody to the sphere, but that doesn't help and make the sphere act all wonky (with or without gravity).
Any thoughts?
Answer by taddmencer · Aug 19, 2011 at 06:57 PM
I think I figured this out.
Create an empty game object and put your player within that object. Make sure they're on the same XYZ.
IN the object give it a Character Controller and put the tilt script that I mention attached to that empty object.
On the player object (in my case, a sphere) make sure it has a sphere collider and mesh renderer (default) and add a rigid body with gravity off.
This worked for me. I'm doing a top down pinball like proof of concept, this seems to have worked.
Eh no. That didn't work like I thought it did. I faked myself out.
Answer by taddmencer · Sep 06, 2011 at 07:10 PM
Ok, so .. still having issues.
What I'm attempting here is a 2D side scroller. When I tilt an ipad left or right, the character moves. Tap the lower right, the character jumps.
Initially no problem. HOWEVER, the only collider that works is when a flat object us being used for the "floor" or the Y axis .. so, if I walk to the X of an object, my character will waltz right through. HOWEVER, the character can jump on top of the object, say a regular cube with a box collider.
The script I'm using for the tilt seems to be the culprit though with my limited coding brain power I can only stick my tongue out at it in frustration.
Here is the code:
var speed = 20.0;
function Update () {
var dir : Vector3 = Vector3.zero;
dir.x = -Input.acceleration.y;
if (dir.sqrMagnitude > 1)
dir.Normalize();
dir *= Time.deltaTime;
transform.Translate (dir * speed);
}
As you see, nothing crazy.
I'm using the prefab Dual TouchPads that come with the 'Standard Assets (Mobile)' and I just disable the left movement controller to use ONLY the pad tilting.
I'd really appreciate any help, thoughts or insults on this ... I'm feeling mildly retarded here.
Hi taddmencer, I haven't gone through the code but I experienced a similar problem doing a variation on a rollaball. It turned out that the physics was going to 'sleep' on my ball, so I had to add an add force of 0,0,0 to it. Although the force was zero, it did keep the physics awake on the ball and fixed the unusual collision problems I was having. Probably not the solution but just something you could try. Cheers Chris
Ok, I added a constant force to my player (which also added a rigidbody) and that actually caused the character to drop completely through the course. I remove gravity from my rigid body and that didn't help either.
I'll have to look some more and see if there is something more along this sleeping physic path.
Thanks for pointing me in a direction!
Answer by taddmencer · Oct 04, 2011 at 08:59 PM
OK, I've not figured this out. I can't get any meshes that are imported to accept a collider IF I'm using this accelerator input script provided by Unity. And only the top of a box mesh will register a collider on a pre-generated cube within Unity itself.
Not sure what to do at this point in regards to this. The higher-ups in my company want to see this work, so do I. But sadly nothing yet.
If anyone has any ideas, let me know. Otherwise ... back to the drawing board!
Your answer
Follow this Question
Related Questions
Input.acceleration reading Issue 1 Answer
Smooth tilt accelerometer 1 Answer
Accelerometer angle limit 1 Answer