void HandleCollideForCoconut(Coconut coconut)
 {
     // Remove coconut from the world after it has time to fall offscreen.
     coconut.RunAction(SCNAction.Wait(3.0), () => {
         coconut.RemoveFromParentNode();
         GameLevel.Coconuts.Remove(coconut);
     });
 }
        void SetupGetCoconutAnimation()
        {
            SCNAnimationEventHandler pickupEventBlock = (CAAnimation animation, NSObject animatedObject, bool playingBackward) => {
                if (coconutInHand != null)
                {
                    coconutInHand.RemoveFromParentNode();
                }

                coconutInHand = Coconut.CoconutProtoObject;
                rightHand.AddChildNode(coconutInHand);
                hasCoconut = true;
            };

            CAAnimation getAnimation = LoadAndCacheAnimation(GameSimulation.PathForArtResource("characters/monkey/monkey_get_coconut"), "monkey_get_coconut-1");

            if (getAnimation.AnimationEvents == null)
            {
                getAnimation.AnimationEvents = new SCNAnimationEvent[] { SCNAnimationEvent.Create(0.4f, pickupEventBlock) }
            }
            ;

            getAnimation.RepeatCount = 1;
        }

        void SetupThrowAnimation()
        {
            CAAnimation throwAnimation = LoadAndCacheAnimation(GameSimulation.PathForArtResource("characters/monkey/monkey_throw_coconut"), "monkey_throw_coconut-1");

            throwAnimation.Speed = 1.5f;

            if (throwAnimation.AnimationEvents == null || throwAnimation.AnimationEvents.Length == 0)
            {
                SCNAnimationEventHandler throwEventBlock = ThrowCoconut;

                throwAnimation.AnimationEvents = new SCNAnimationEvent[] { SCNAnimationEvent.Create(0.35f, throwEventBlock) };
            }

            throwAnimation.RepeatCount = 0;
        }

        void ThrowCoconut(CAAnimation animation, NSObject animatedObject, bool playingBackward)
        {
            if (!hasCoconut)
            {
                return;
            }

            SCNMatrix4 worldMtx = coconutInHand.PresentationNode.WorldTransform;

            coconutInHand.RemoveFromParentNode();

            Coconut         node = Coconut.CoconutThrowProtoObject;
            SCNPhysicsShape coconutPhysicsShape = Coconut.CoconutPhysicsShape;

            node.PhysicsBody                  = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Dynamic, coconutPhysicsShape);
            node.PhysicsBody.Restitution      = 0.9f;
            node.PhysicsBody.CollisionBitMask = GameCollisionCategory.Player | GameCollisionCategory.Ground;
            node.PhysicsBody.CategoryBitMask  = GameCollisionCategory.Coconut;

            node.Transform = worldMtx;
            GameSimulation.Sim.RootNode.AddChildNode(node);
            GameSimulation.Sim.GameLevel.Coconuts.Add(node);
            node.PhysicsBody.ApplyForce(new SCNVector3(-200, 500, 300), true);
            hasCoconut = false;
            isIdle     = true;
        }
    }
		void HandleCollideForCoconut (Coconut coconut)
		{
			// Remove coconut from the world after it has time to fall offscreen.
			coconut.RunAction (SCNAction.Wait (3.0), () => {
				coconut.RemoveFromParentNode ();
				GameLevel.Coconuts.Remove (coconut);
			});
		}