简体   繁体   中英

Detect collision between particles and nodes in SceneKit

I have few nodes with a Kinematic phyisicsBodyType and I want it to interact with some particles System, and by that I mean that I want to detect collision and execute some code at the moment when node collide with nay particle from an particle system. I've found a way by adding an event handler, but I'm not quite sure how can I use it( link to method here ).

Can someone explain me how can I use that event handler(preferred would be to explain me in Swift), or otherwise can you give me another idea?

In the end was very simple. First, you have to assign an array of nodes to the colliderNodes property of particle system. After that, code in swift looks something like that:

    particleSystem.handleEvent(SCNParticleEvent.Collision, forPropierties:[SCNParticlePropertyContactPoint], withBlock: {
        (data: UnsabeMutablePointer<UnsafeMutablePointer<Void>>, dataStride: UnsafeMutablePointer<Int>, indicies: UnsafeMutablePointer<UInt32>, count:Int) in 
        //code on detection collision goes here
})

Every parameter is briefly explained right in apple documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM