Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by crittauk · Jul 12, 2020 at 11:24 PM · audioparticlesvelocityparticle system

How to get particle velocity to affect audio amplitude

Hi, I'm new to Unity. I have particle collisions triggering audio but I'm unsure on how to get their velocity to control the audio amplitude.

The audio is coming from a puredata patch using Kalimba but an answer related to a general audio source would still be very useful.

Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ifurkend · Jul 13, 2020 at 12:47 AM

You can refer to OnParticleCollision and ParticleCollisionEvent. Since the "velocity" you get from collision event is a vector3, you need to calculate its magnitude before apply it for the audio amplitude/volume. The following code also remaps and clamps the speed value to better control the resultant volume. To understand the speed range of your particle system, look at the "Particle Effect" console at the bottom-right corner of the Scene view, this can help you better estimate the proper speed range.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class ParticleCollisionMessage : MonoBehaviour
 {
     public ParticleSystem _particleSystem;
     public AudioSource _audioSource;
     public Vector2 _speedRange = new Vector2(0f,1f);
     public Vector2 _volumeRange = new Vector2(0f,1f);
     public List<ParticleCollisionEvent> collisionEvents;
 
     void Start()
     {
         if (_particleSystem == null) _particleSystem = this.GetComponent<ParticleSystem>();
         collisionEvents = new List<ParticleCollisionEvent>();
     }
 
     void OnParticleCollision(GameObject other)
     {
         int numCollisionEvents = _particleSystem.GetCollisionEvents(other, collisionEvents);
         int i = 0;
         while (i < numCollisionEvents)
         {
             float _speed = collisionEvents[i].velocity.magnitude;
             float _volume = Remap(_speed, _speedRange.x, _speedRange.y, _volumeRange.x, _volumeRange.y);
             _volume = Mathf.Clamp(_volume, _volumeRange.x, _volumeRange.y);
             _audioSource.volume = _volume;
             _audioSource.Play();
             i++;
             //Debug.Log(_volume);
         }
     }
     
     float Remap (float _value, float _low1, float _high1, float _low2, float _high2) {
         return _low2 + (_value - _low1) * (_high2 - _low2) / (_high1 - _low1);
     }
 }


Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image crittauk · Jul 13, 2020 at 04:00 AM 0
Share

Thanks @ifurkend , that all makes sense and I've implemented the code in my project. I'm just having trouble with adapting line #29.

I have an amplitude slider in my puredata patch ranging from 0-127. I'm using Kalimba to link Unity to the puredata patch and I'm not sure how to reference the slider ins$$anonymous$$d of the Audio Source volume parameter.

I'm not sure if this helps for Kalimba context/syntax, but there's a pull request relating to the volume slider here

Thanks again and I'd be grateful for any futher assistance.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

244 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Particle System Particles Not Following Rotation 1 Answer

Particles emited from bellow the cone base shell 2 Answers

RayCast on particle system 0 Answers

Making particle effect script on collision 0 Answers

Little dust particles after player jump hitting ground 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges