{"id":2658,"date":"2019-12-17T11:01:55","date_gmt":"2019-12-17T02:01:55","guid":{"rendered":"https:\/\/blog.criware.com\/?p=2658"},"modified":"2019-12-17T12:11:04","modified_gmt":"2019-12-17T03:11:04","slug":"creating-dynamic-scrape-sounds-in-unity-using-adx2","status":"publish","type":"post","link":"https:\/\/blog.criware.com\/index.php\/2019\/12\/17\/creating-dynamic-scrape-sounds-in-unity-using-adx2\/","title":{"rendered":"Creating Dynamic Scrape Sounds in Unity using ADX2"},"content":{"rendered":"<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Introduction<\/h2>\n<p>In <a href=\"https:\/\/blog.criware.com\/index.php\/2019\/11\/22\/creating-dynamic-impacts-sounds-in-unity-using-adx2\/\" target=\"_blank\">last month\u2019s blog<\/a>, we looked at enhancing player immersion by creating a system which better reflected physically informed impact sounds. This month, we are going to extend on that by creating a system which reflects physical scraping as well. Together, these two systems should give us a holistic system for most of the rigid physical interactions that might take place in a game.<\/p>\n<p><!-- video and download start --><\/p>\n<div style=\"max-width: 800px; margin: 0 auto; margin-bottom: 20px;\">\n<div style=\"width: 800px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-2658-1\" width=\"800\" height=\"450\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/1912_SurfaceScaler.mp4?_=1\" \/><a href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/1912_SurfaceScaler.mp4\">https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/1912_SurfaceScaler.mp4<\/a><\/video><\/div>\n<\/div>\n<p><!-- download start --><\/p>\n<div style=\"max-width: 800px; margin: 0 auto; margin-bottom: 20px; text-align:center;\">\n<a style=\"display: inline-block; border: 1px solid #ccc; padding: 20px;\" href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/1912_SurfaceScaler_AtomCraftProject.zip\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1813\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2018\/06\/zip.png\" alt=\"zip\" width=\"80\" height=\"78\"><br \/>\n1912_SurfaceScaler_AtomCraftProject.zip<\/a>\n<\/div>\n<p><!-- video and download end --><\/p>\n<p><em>This project was created using CRIWARE SDK for Unity V2.99.00 and Unity V2019.2.10f1 <\/em><\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Atom Craft<\/h2>\n<p>The setup for our scrape system will be much the same as for the dynamic impacts. The goal is to create a system which gets louder and more exciting, the faster the ball character moves. To achieve this, we need to set up several AISACs for adjusting volume intensity of our different layers, as well as for controlling effects and modulations.<\/p>\n<p>Since scrapes are continuous, we can make use of looped audio. Again, 3 dynamic levels tend to be enough for meaningful variation, so we can simply:<\/p>\n<ul>\n<li>Create a Polyphonic Cue named \u201cCue_Scrape\u201d<\/li>\n<li>Drag in each dynamic layer Material (which will automatically create our Tracks)<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/22-1.png\" alt=\"22-1\" width=\"826\" height=\"328\" class=\"alignnone size-full wp-image-2673\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/22-1.png 826w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/22-1-300x119.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/22-1-768x305.png 768w\" sizes=\"auto, (max-width: 826px) 100vw, 826px\" \/><\/p>\n<p>Next up, we can create another AISAC-Control called \u201cAISAC_ScrapeIntensity\u201d, which will be used to send control signal to all our related AISACs. We can then set up volume curves on each Track as we did for each Cue Link in last month\u2019s blog.<\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Effects<\/h2>\n<p>Since the dynamic layers might sound a little disconnected, we can employ some additional effects to blend and generally sweeten them. Here are a few ways that we can take advantage of the flexibility of AISACs:<\/p>\n<p>Any sort of \u201cloudening\u201d effects can be used on an FX bus, and send levels controlled via an AISAC. This helps to add loudness over-and-above the original samples, which might not be too different in terms of raw amplitude. We can:<\/p>\n<ul>\n<li>Create DSP Bus in our DspBusSetting named \u201cFXBUS\u201d<\/li>\n<li>Add Distortion and Limiter Effects<\/li>\n<li>Adjust values in the Inspector to preference<\/li>\n<li>On Cue_Scrape, create a new AISAC\n<ul>\n<li>AISAC Name \u2013 \u201cfx-send\u201d<\/li>\n<li>AISAC Control \u2013 AISAC_ImpactIntensity<\/li>\n<li style=\"color:#ff66ab; font-weight:bold;\">AISAC Graph Type \u2013 BusSend1 (FXBUS)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Low-cutoff can be used to imply quietness. This help to make intensity scaling sound a bit more natural than only turning the gain down.<\/p>\n<ul>\n<li>On Cue_Scrape, create a new AISAC\n<ul>\n<li>AISAC Name \u2013 \u201clow-cutoff\u201d<\/li>\n<li>AISAC Control \u2013 AISAC_ImpactIntensity<\/li>\n<li style=\"color:#9966ff; font-weight:bold\";>AISAC Graph Type \u2013 Bandpass Cutoff Low<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Finally, some subtle pitch scaling can be used to change the playback rate as a result of character speed. Since the ball will be rotating a certain amount of times per minute, it makes sense that this should influence pitch\/frequency.<\/p>\n<ul>\n<li>On Cue_Scrape, create a new AISAC\n<ul>\n<li>AISAC Name \u2013 \u201cpitch\u201d<\/li>\n<li>AISAC Control \u2013 AISAC_ImpactIntensity<\/li>\n<li style=\"color:#2f5496; font-weight:bold\">AISAC Graph Type \u2013 Pitch<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/22-3.png\" alt=\"22-3\" width=\"1512\" height=\"516\" class=\"alignnone size-full wp-image-2676\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/22-3.png 1512w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/22-3-300x102.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/22-3-768x262.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/12\/22-3-1024x349.png 1024w\" sizes=\"auto, (max-width: 1512px) 100vw, 1512px\" \/><\/p>\n<p>The curves can then be adjusted roughly as above. Each curve is colour-coded based on the Graph Type, to help distinguish each of the parts ( the explanations above have been coloured to correspond with these). These curves are best tested iteratively throughout the design process using the Session View.<\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Unity<\/h2>\n<p>The code needed is much like last month\u2019s, but this time we will use the <em>OnCollisionStay <\/em>and <em>OnCollisionExit <\/em>events instead.<\/p>\n<pre><code class=\"hljs php\">using System.Collections;\r\nusing System.Collections.Generic;\r\nusing UnityEngine;\r\n\r\npublic class SurfaceScrape : MonoBehaviour\r\n{\r\n    CriAtomSource source;\r\n    bool isPlaying = false;\r\n    Rigidbody sphereRigidBody;\r\n\r\n    [SerializeField]\r\n    private float scaledScrapeVelocity;\r\n\r\n    void Start()\r\n    {\r\n        source = gameObject.GetComponent<CriAtomSource>();\r\n        sphereRigidBody = gameObject.GetComponent<Rigidbody>();\r\n    }\r\n\r\n    private void OnCollisionStay(Collision collision)\r\n    {\r\n        if (!isPlaying)\r\n        {\r\n            source.Play();\r\n            isPlaying = true;\r\n        }\r\n\r\n        scaledScrapeVelocity = Mathf.Clamp((Mathf.Abs(sphereRigidBody.velocity.x) + Mathf.Abs(sphereRigidBody.velocity.z)) \/ 25, 0f, 1f);\r\n        source.SetAisacControl(\"AISAC_ScrapeIntensity\", scaledScrapeVelocity);\r\n    }\r\n\r\n    private void OnCollisionExit(Collision collision)\r\n    {\r\n        if (isPlaying)\r\n        {\r\n            source.Stop();\r\n            isPlaying = false;\r\n        }\r\n    }\r\n}\r\n<\/code>\r\n<\/pre>\n<p>Since our <em>Collision<\/em> method is only able to return the impact velocity, we need to refer to the Rigidbody directly to access continuous velocity information. Also, to ensure that the sound isn\u2019t triggered on every frame, we can use an <em>isPlaying <\/em>Boolean to keep track of the current state.<\/p>\n<p>Our scape velocity is also scaled similarly to our impact velocity. However, since Rigidbody velocity can return negative values, we need to ensure that we get the absolute values. Furthermore, since the ball is only rolling around on a flat plane in this Scene, we can refer to velocity in only the x and z axes for simplicity.<\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Conclusion<\/h2>\n<p>And that concludes our dynamic surface interaction mini-series. This should give you the tools to create some impressive sounding physics-based interactions. This system could be further expanded to make use of Unity\u2019s tag or terrain systems to denote different surface or object types. That way the surface and object interactions are not only responsive but also accurate to their respective materials.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In last month\u2019s blog, we looked at enhancing player immersion by creating a system which better reflected physically informed<\/p>\n","protected":false},"author":2,"featured_media":2661,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[5,7],"tags":[],"class_list":["post-2658","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-adx","category-tutorials"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/2658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/comments?post=2658"}],"version-history":[{"count":14,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/2658\/revisions"}],"predecessor-version":[{"id":2685,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/2658\/revisions\/2685"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media\/2661"}],"wp:attachment":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media?parent=2658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/categories?post=2658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/tags?post=2658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}