Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Created January 18, 2018 14:01
Show Gist options
  • Save rdelrosario/9b4c37ce83021c59e3cebd9f90e9fba3 to your computer and use it in GitHub Desktop.
Save rdelrosario/9b4c37ce83021c59e3cebd9f90e9fba3 to your computer and use it in GitHub Desktop.
Pokeball
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
var forcePower = 10;
base.TouchesBegan(touches, evt);
var pointOfView = this.SceneView.PointOfView;
var transform = pointOfView.Transform;
var location = new SCNVector3(transform.M41, transform.M42, transform.M43);
var orientation = new SCNVector3(-transform.M31, -transform.M32, -transform.M33);
var position = location + orientation;
var pokeball = new SCNNode()
{
Geometry = SCNSphere.Create(0.15f),
};
pokeball.Geometry.FirstMaterial.Diffuse.ContentImage = UIImage.FromBundle("pokeball");
pokeball.Position =position;
pokeball.PhysicsBody = SCNPhysicsBody.CreateDynamicBody();
pokeball.PhysicsBody.PhysicsShape = SCNPhysicsShape.Create(pokeball);
pokeball.PhysicsBody.ContactTestBitMask = (int) BitMaskCategory.Pokemon;
pokeball.PhysicsBody.CategoryBitMask = (int)BitMaskCategory.Pokeball;
pokeball.PhysicsBody.ApplyForce(new SCNVector3(orientation.X*forcePower,orientation.Y*forcePower,orientation.Z*forcePower),true);
SceneView.Scene.RootNode.AddChildNode(pokeball);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment