Adding UIGravityBehavior and UIPushBehavior after a collision takes place in iOS 7

I'm messing around with the new physics API in iOS 7.

I decided I would make a simple game, I have a character who can move around the screen at a tap of the finger, periodically, shapes fly up from the bottom and if they hit the character it's game over.

I have implemented all of the above and it works great, however, the only thing that doesn't is the character falling when a shape collides with him.

All collisions work, my problem is trying to make the character fall when the collision takes place. Because I don't want the character to be able to fall before this (lets say he's levitating while trying to avoid shapes) I decided to add the character to the gravity when the collision happens, and it does, but first, the character shoots upwards as the collision animation continues.

Is there any way to prevent the collision animation from happening? Is there a better way?

Here is my code in the collisionBehavior:beganContactForItem:withBoundaryIdentifier:atPoint: method:

//  Main Character
//
if ([item isEqual:self.mainCharacter]) {
    [self.collision removeItem:item];

    //          Push
    //
    UIPushBehavior *pushBehaviour = [[UIPushBehavior alloc] initWithItems:@[self.mainCharacter] mode:UIPushBehaviorModeInstantaneous];
    [pushBehaviour setPushDirection:CGVectorMake(0.0f, 1.0f)];
    [self.animator addBehavior:pushBehaviour];
    [pushBehaviour setActive:YES];

    [self.gravity addItem:item];
}

Answers


It turns out I should have been using the collisionBehavior:beganContactForItem:withItem:atPoint: and testing BOTH items in this method to see if it is the mainCharacter


Need Your Help

Exact meaning of "new" on member declarations

c# .net oop inheritance member

I have seen methods that are declared like this:

Get the selected text (not selected value) of an asp:dropdownlist in code behind using C#

c# asp.net code-behind

I need to read in the code behind the selected text (not the value) in the dataTextField of a dropdownlist that is nested in a FormView.