简体   繁体   English

检测SceneKit中粒子和节点之间的碰撞

[英]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. 我有几个带有Kinematic phyisicsBodyType的节点,我希望它与某些粒子System进行交互,我的意思是我想检测碰撞并在节点与粒子系统中的nay粒子碰撞时执行一些代码。 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? 有人可以解释我如何使用该事件处理程序(首选是在Swift中解释我),或者你能否给我另一个想法?

In the end was very simple. 最后很简单。 First, you have to assign an array of nodes to the colliderNodes property of particle system. 首先,您必须将一个节点数组分配给粒子系统的colliderNodes属性。 After that, code in swift looks something like that: 之后,swift中的代码看起来像这样:

    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 . Apple文档中简要解释了每个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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