Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Created January 18, 2018 04:03
Show Gist options
  • Save rdelrosario/55c32cffa468e2a58f704539fd9c809d to your computer and use it in GitHub Desktop.
Save rdelrosario/55c32cffa468e2a58f704539fd9c809d to your computer and use it in GitHub Desktop.
ARKit PhysicsDelegate
public class PhysicsDelegate : SCNPhysicsContactDelegate
{
IList<SCNNode> animatedNodes=new List<SCNNode>();
public override void DidBeginContact(SCNPhysicsWorld world, SCNPhysicsContact contact)
{
var nodeA = contact.NodeA;
var nodeB = contact.NodeB;
SCNNode target = null;
if (nodeA.PhysicsBody.CategoryBitMask == (int)BitMaskCategory.Pokemon)
{
target = nodeA;
}
else if (nodeB.PhysicsBody.CategoryBitMask == (int)BitMaskCategory.Pokemon)
{
target = nodeB;
}
if (target != null && !animatedNodes.Contains(target))
{
var targetScale=target.Scale;
animatedNodes.Add(target);
target.RunAction(SCNAction.Sequence(new SCNAction[]{
SCNAction.ScaleTo(0, 1.0f),
SCNAction.ScaleTo(targetScale.X, 2.0f),
}),()=>{
animatedNodes.Remove(target);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment