How to set the AttractionCenter for a ParticleEmitterComponent in a System with real time updates

I am trying to achieve an effect such that the particles of a particle system are attracted to my hand entity. The hand entity is essentially an AnchorEntity that is tracking my right hand.

let particleEmitterEntities = context.entities(matching: particleEmitterQuery, updatingSystemWhen: .rendering)
        
for particleEmitterEntity in particleEmitterEntities {
            if var particleEmitter = particleEmitterEntity.components[ParticleEmitterComponent.self] {
                particleEmitter.mainEmitter.attractionCenter = rightHandEntity.position(relativeTo: nil)
// trying to get the world space position of the hand 
// I also tried relative to particleEmitterEntity 
                particleEmitterEntity.components[ParticleEmitterComponent.self] = particleEmitter
            } else {
                fatalError("Cannot find particle emitter")
            }
        }

The particle attraction center doesn't seem to update

Another issue I am noticing here that My particle system doesn't show the particle image a lot of times and just renders a placeholder square when I do this, when I comment this code out I get the right particle image. I believe this is due to the number of times this loop runs to update the position of the attraction center.

What is the right way to do an effect where the particles are attracted to my hand.

Answered by doomdave in 809894022

@arthurfromberlin this is actually right! But I changed that property somewhere else on the particle emitter component

I had to enable the Particles in Local Space and Fields in Local Space flag for this to work

I experimented a little more and realized that It actually is setting the attractionCenter, but for some reason the effect is very minimal, I believe this has something to do with the coordinate space conversion as the attraction center needs to be in local space and my hand entity is not in the local space.

I tried using entity.convert(Position: handEntity.Position, from: handEntity. Where entity is my particle system but still it is not working as expected.

Hi, what is your https://developer.apple.com/documentation/realitykit/particleemittercomponent/simulationspace property currently set to? Also is this set to true or false: https://developer.apple.com/documentation/realitykit/particleemittercomponent/particlesinherittransform ?

Accepted Answer

@arthurfromberlin this is actually right! But I changed that property somewhere else on the particle emitter component

I had to enable the Particles in Local Space and Fields in Local Space flag for this to work

How to set the AttractionCenter for a ParticleEmitterComponent in a System with real time updates
 
 
Q