Adding force to a rigid body fails on iOS.

Hey guys,

I have a cube that uses the unity-included “Metal” physics material. When my character controller “pushes” it from one of its sides, the character controller script does an AddForce to the cube’s rigid body. This allows the character to push the cube, and it works great on PC/Mac/Webplayer. When I compile the same project for iOS however, the player is unable to push the cube.

I know the force is working to an extent, because I can move the cube a few pixels if i keep pushing it for a long time. I also have a similar pushable cube suspended in the air by a rope that I can push on the iOS build with no problems. This leads me to believe that the problem might be related to friction. Does the unity-included “Metal” physics material work on iOS? Is there any other reason anyone can think of for why my pushable cube physics is behaving differently on iOS?

Any help with this is greatly appreciated. Thanks!

EDIT

Here is the character controller’s “push” code. The context here is that everything basically occurs on a 2D plane in a sidescroller-like fashion, so the player can only push an object either left or right depending on which direction they are pushing from. Also, the cube has locked rotation so that it’s corners do not “catch” on the floor.

function OnControllerColliderHit ( hit : ControllerColliderHit ) {
	// push objects
	if ( hit.gameObject.CompareTag( 'Pushable' ) ) {
		var body : Rigidbody = hit.rigidbody;
		if ( transform.position.y > hit.collider.bounds.min.y && transform.position.y < hit.collider.bounds.max.y ) {
	
			var pushDirection : float;
			if ( hit.moveDirection.x > 0 ) {
				pushDirection = 1;
			} else {
				pushDirection = -1;
			}
			body.AddForce( Vector3( pushDirection * 30, 0, 0 ) );
		}
	}
}

Ok… I don’t know… The only thing that I can think is the method OnControllerColliderHit add force each time that is called.

Try to figure out how many times it is called in each platform. Add a Debug.Log to print each frame and other right after the AddForce.

You should execute all physic logic inside the FixedUpdate
(Unity - Scripting API: MonoBehaviour.FixedUpdate()). I think that simply moving “body.AddForce( Vector3( pushDirection * 30, 0, 0 ) );” will fix.