Is there a code to make a particle system play when pressed then reset
Hi @Gavin_Durbin! I don’t know how you want to use it exactly, but I think you can use something like te script below. For this script your entity with the particle system need also a rigidbody and collision component.
var PickerRaycast = pc.createScript('pickerRaycast');
// initialize code called once per entity
PickerRaycast.prototype.initialize = function() {
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onSelect, this);
};
PickerRaycast.prototype.onSelect = function (e) {
var cam = this.app.root.findByName('Camera');
var from = cam.camera.screenToWorld(e.x, e.y, cam.camera.nearClip);
var to = cam.camera.screenToWorld(e.x, e.y, cam.camera.farClip);
var result = this.app.systems.rigidbody.raycastFirst(from, to);
if (result && result.entity.particlesystem) {
result.entity.particlesystem.reset();
result.entity.particlesystem.play();
}
};
3 Likes