Search Unity

Heart Rate and Beat Monitor

Discussion in 'Assets and Asset Store' started by SketchWork, Jan 3, 2013.

  1. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254

    Description

    The Heart Rate and Beat Monitor is an easy to use script that will add the heart monitor to your games and projects. This C# script is very easy to use and can be implemented in just a few clicks. The script should also be compatible and performance friendly with all of the platforms supported by Unity3D.

    $Attack_25.jpg $FlatLine_25.jpg $FullScreenOnblack_25.jpg $Corner_25.jpg

    Features
    • Full support for Unity 3.5 and Unity 4+ (Free and Pro).
    • Use to show your players health and damage.
    • Control the heart rate.
    • Activate the "Flatline" when your player is dead.
    • Heart blip and monitor line fade out nicely.
    • Colour heart line depending on player health.
    • Full sound effects can be turned on if required.
    • Control the size and positioning.
    • Clean, short and simple C# code.
    • No external DLLs or external resources.
    • Full documentation included.
    • Fully documented examples.

    InspectorNew2-0.jpg

    Use the Heart Rate and Beat Monitor for your player health, but it exists in 3D space so you can also place it anywhere in your scene. A life support monitor for example.

    Add that little something special to your projects and grab yourself a bargin with the Heart Rate and Beat Monitor.

    Asset Store Link: "Get the Heart Rate and Beat Monitor".

    Video Demo

    Video Demo 2

    Version History

    Version 2.0
    Added support for Unity 4.5.
    Added the ability to colour the heart rate line easily.
    Added brand new custom inspector component.

    Version 1.5
    Added full support for Unity 3.5 and Unity 4+.
    Updated support email details.

    Version 1.4
    Added heart beat sound effects.
    Added flatline sound effect.
    Added “Enable Sound” control.
    Added “Heart Volume” control.

    Version 1.3
    Updated documentation to include mobile build optimisation notes.

    Version 1.2
    Updated documentation.

    Version 1.1
    Added full documentation.
    Added code comments.

    Version 1.0
    Initial release.

    Asset Store Link: "Get the Heart Rate and Beat Monitor".
     
    Last edited: Jun 22, 2014
  2. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Does this have audio? Can you hear the heartbeat?
     
  3. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @kenlem: It doesn't at the moment as I wasn't sure if this would be annoying, but it is easy to do so I'll add it to the next version with an option to turn it on and off.
     
  4. UnleadedGames

    UnleadedGames

    Joined:
    Feb 17, 2008
    Posts:
    242
    Very interested but would love to see a video of it an action first.
     
  5. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @UnleadedGames: That's not a problem. I'll put up a couple of videos for you.
     
    UnleadedGames likes this.
  6. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    How many drawcalls does this add?
     
  7. Tapgames

    Tapgames

    Joined:
    Dec 1, 2009
    Posts:
    242
    This looks really nice! Cant wait to see a video of it.
     
  8. fano_linux

    fano_linux

    Joined:
    Jan 1, 2012
    Posts:
    909
    I'm intrested too, but i need to see the video and some more details, like draw calls, how easy is to change it my way, a tutorial to add the asset...

    "will that blood come too?"
     
  9. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @fholm
    @fano_linux:
    Depending on what you set the heart rate to it will only add between 2 and 3 calls.

    @Tapgames: Just looking at getting a video up soon for you to see it in action, but no unfortunately the blood doesn't come with the package :)
     
  10. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    SketchWork: This makes it essentially useless for mobile tho, since 3 drawcalls (and also the "dot" I assume) is way to much to pay for such a small effect =(
     
  11. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @fholm: That does include the dot, but I'll look at ways to maybe reduce this for mobile.
     
  12. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Bought and checked the source. You're going to want to get rid of the call to instantiate for mobiles.
     
  13. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @kenlem: Thanks for the purchase and more importantly the feedback. I'll look at adding some additional optimisations.

    Thanks again.

    Justin
     
  14. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @UnleadedGames
    @Tapgames
    @fano_linux:
    Added a demo video to the top post.
     
    Last edited: Jan 4, 2013
  15. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    Package updated with some additional documentation.
     
  16. UnleadedGames

    UnleadedGames

    Joined:
    Feb 17, 2008
    Posts:
    242
    Thank you for the video, would there be any reason this wouldn't work in Unity 3.5.7 if I were to import it into Unity 4 then move it my Unity 3.5.7 project folder?
     
  17. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @UnleadedGames: There should be no reason at all. It only defaults to Unity 4 because that is what I exported it from, so should work perfectly :)
     
  18. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    I have added some mobile optimisation notes. For mobile users if you turn off the blip you can get the number of draw calls down to 1 to 2. I'm looking at getting this to just 1 for the next release for mobile users.

    Have fun and happy new year everyone.
     
  19. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    New version with full heart sound effects and flatline sound effect submitted to asset store. Waiting for approval :)

    Enjoy!
     
  20. hellraizerhhh

    hellraizerhhh

    Joined:
    May 26, 2010
    Posts:
    619
    My only problem is that the rhythm strip is not a normal baseline, other than that its pretty cool. A heart beat monitor would show a P wave, QRS complex, and a T wave. Right now your player does not have a P wave, so no AV node depolarization. You also have a lot of noise or artifacts between the beats. The strip should be completely clean between beats, unless of course he has a heart block in which case he will need surgery or die.

    Your normal sinus rhythm should look like this http://www.richacls.com/blog/wp-content/uploads/2010/07/Normal-Sinus-Rhythm.png

    Dont forget, although your hear rate increases, there should be no change in the appearance of the lines. The only change would be that the beats would be closer together. Any variation in the beats would indicate a problem with the heart.
     
    Last edited: Jan 8, 2013
  21. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @hellraizerhhh: Thanks for the feedback. I think I was originally going for a more fictitious look and feel, but I think what I'll do is add an option for a realistic baseline too. I'll make the adjustments for the next version. My wife is a nurse - maybe I should have asked her to take a look too :)

    Thanks again.
     
  22. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    Version 1.4 has been submitted to the Asset Store and now features full sound effects which of course can be turned on and off as needed.

    First post updated with release notes.
     
  23. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    Thank you to everyone who has purchased this asset so far. Version 1.4 has gone live in the asset store today which now includes full sound effects.

    Enjoy and thanks again.
     
  24. Renan-Reis

    Renan-Reis

    Joined:
    Dec 9, 2012
    Posts:
    11
    I put the heart monitor as health bar in my game and it was pretty cool, here's a video (you can see the monitor on top of the tablet, when the camera zooms). It was very easy to use.

     
  25. mrbdrm

    mrbdrm

    Joined:
    Mar 22, 2009
    Posts:
    510
    i got a problem with blip monitor height if i set it low ( 0.01) the beats become random and not on the same level
    also i can't find a way to make it in the same position in the screen, every time i change the reselotion it gets off place.
     
  26. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    I'll take a look for you, can you post an image showing where you are trying to put it and the size of it.
     
  27. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    I have checked and if you are changing the Height Modifier to 0.01 it makes the blip peaks very small so you can't really see them.

    The control is just like any other control in regards to position so if you want it to always been in the centre and at the top of the screen (like Renan Reis's example above) you can calculate the screen size and divide by 2 to get the centre and position accordingly. If you just position it in the inspector and move the camera at runtime the control will also move unless you have a dedicated GUI camera which doesn't move, but you will still need to calculate the position if the resolution changes.
     
    Last edited: Feb 9, 2013
  28. mrbdrm

    mrbdrm

    Joined:
    Mar 22, 2009
    Posts:
    510
    if i set it anything bigger it will take more space than it should, i need it to be in the top left screen, here is how i am doing it :
    there is a separate camera for my UI
    i added a NGUI sprite then i attached UI anchor script (so it stay at the top left all the time) then i added the SWP script to the sprite.
    the sprite stay as it should no problem but the heart beats do not.
    here at 0.01


    and here with 0.06
     
  29. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    I few things that might be worth taking a look at.

    How are you shrinking the controller? If you are using a perspective camera have you tried pushing it back on the Z position or the projection size if using an orthographic camera instead of shrinking it drastically using the monitor width and height modifiers and then use the modifiers to fine tune?

    Also, NGUI will create you an orthographic camera with a projection size of 1 which could be why your heart controller is so huge to begin with and I think the reason why your heart line is moving around is probably because the HeartMonitorBlip and HeartMonitorTrail prefabs are being created on the default layer and are being rendered with the default scene camera which is not effected by the anchor.

    Last thing, have you checked out Example 1 (Overlay) as this looks pretty much what you are trying to accomplish with regards to size. You'll just need to anchor it to the top left and you are done.

    Let me know how you get on.

    Take care and all the best. Justin
     
    Last edited: Feb 10, 2013
  30. mrbdrm

    mrbdrm

    Joined:
    Mar 22, 2009
    Posts:
    510
    thanks for the support
    i got the position to work after adding an empty game object and make it serve as a pivot for the HRM then i attached the UIAnchor script to it.
    the only remaining problem now is NGUI camera size, how do i fix this ? do i must add a third camera to my game ? isn't making a camera only for this is a huge performance loose ?
     
  31. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    Glad you sorted out the anchoring. If the camera is only going to project the HRM and cull everything else then there should not be any performance loss. Give it a try and let me know how it goes. All the best, Justin.
     
  32. GREBENOTS

    GREBENOTS

    Joined:
    Jan 24, 2013
    Posts:
    44
    Thanks for this little plugin. Can you provide a simple example of how to set the bpm variable with a javascript script? I'm pretty new, and I really don't know how to interface c# variables with javascript (which is the only option for me right now).

    Thanks!
     
  33. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    Firstly, thanks for the purchase - much appreciated.

    No problem at all. I'll put together a quick example for you tomorrow on how to interface with Javascript.
     
  34. GREBENOTS

    GREBENOTS

    Joined:
    Jan 24, 2013
    Posts:
    44
    Thanks a ton SketchWork. And thank you for the quick reply.
     
  35. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @GREBENOTS:

    To access from JScript you need to put the SWP_HeartRateMonitor c# script into the plugin folder.

    1) In the root of your project create a folder called Plugins (if not already there)
    2) Create a folder inside the new Plugin folder called SWP_HeartRateMonitor
    3) Move the script SWP_HeartRateMonitor \ Scripts \ SWP_HeartRateMonitor.cs file into this new folder so it should now be:

    Plugins \ SWP_HeartRateMonitor \ SWP_HeartRateMonitor.cs

    This makes sure it is compiled into the editor for use in JScript

    4) Now you should be able to access it from your own JScript files. For example: Open the SWP_HeartRateExample1(FullScreen) project.
    5) Create a new JScript file and add the following code:

    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. var HeartBeat: SWP_HeartRateMonitor;
    5. private var HeartBeat2: SWP_HeartRateMonitor;
    6.  
    7. function Awake()
    8. {
    9.     HeartBeat2 = GameObject.Find("HeartMonitor").GetComponent(SWP_HeartRateMonitor);
    10. }
    11.  
    12. function OnGUI()
    13. {
    14.     if (GUI.Button(Rect(10,10,120,50), "SPEED UP"))
    15.         HeartBeat.BeatsPerMinute = HeartBeat.BeatsPerMinute + 20;
    16.  
    17.     if (GUI.Button(Rect(10,60,120,50), "SLOW DOWN"))
    18.         HeartBeat2.BeatsPerMinute = HeartBeat.BeatsPerMinute - 20;
    19.  
    20. }
    21.  
    5) Add a empty game object and add the new script to it
    6) Drag the HeartMonitor GameObject into the HeartBeat variable on the new gameobject.
    7) Run. One button will speed it up and the other will slow it down. The script uses 2 different methods of calling the HeartBeat:
    i) By inspector assignment (var HeartBeat)
    ii) By assigning with code (private var HeartBeat2)

    I hope this makes sense :)
     
  36. GREBENOTS

    GREBENOTS

    Joined:
    Jan 24, 2013
    Posts:
    44
    Thanks again for your quick reply. I'll be able to get it tested tomorrow, but the code makes perfect sense, so I'm sure it will work. I'll let you know though.
     
  37. GREBENOTS

    GREBENOTS

    Joined:
    Jan 24, 2013
    Posts:
    44
    OK who am I kidding here, I tested it right away! Anyways, your directions work a charm. Thanks again.

    Will a future update allow the capability to change the color of the lines? Green is ideal for my current app, but I may use this in a future app where I'd like to change colors.
     
  38. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @GREBENOTS:

    Really glad you got the JScript working. The colour changer is on my list of todo's so should be available for my next release :)

    Please if you have time give me a little review on the asset store page: https://www.assetstore.unity3d.com/#/content/6034

    - thanks again.
     
  39. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    Version 1.5 is now live in the Asset Store and now has support for both Unity 3.5 and Unity 4+.

    If you have any questions please ask. I am UK time (GMT) and available throughout the day.

    All the best,

    Justin
     
  40. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    Added another YouTube demo (Use for our Time Controller) and features the Heart Beat Monitor. The changes to AngryBots which I used in the demo took only about 5-10 minutes to add complete time control and the Heart Beat.

    Video Demo

    Enjoy!

    Justin
     
  41. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    ANNOUNCEMENT:

    Full Playmaker and UScript support coming soon.
     
    Last edited: Oct 31, 2013
  42. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254

    Features
    • Full support for Unity 3.5 and Unity 4+ (Free and Pro).
    • Use to show your players health and damage.
    • Control the heart rate.
    • Activate the "Flatline" when your player is dead.
    • Heart blip and monitor line fade out nicely.
    • Colour heart line depending on player health. <new 2.0>
    • Full sound effects can be turned on if required.
    • Control the size and positioning.
    • Clean, short and simple C# code.
    • No external DLLs or external resources.
    • Full documentation included.
    • Fully documented examples.

    InspectorNew2-0.jpg
    Custom Inspector <new 2.0>

    Use the Heart Rate and Beat Monitor for your player health, but it exists in 3D space so you can also place it anywhere in your scene. A life support monitor for example.

    Add that little something special to your projects and grab yourself a bargin with the Heart Rate and Beat Monitor.

    Asset Store Link: "Get the Heart Rate and Beat Monitor".

    Version History

    Version 2.0
    Added support for Unity 4.5.
    Added the ability to colour the heart rate line easily.
    Added brand new custom inspector component.

    Version 1.5
    Added full support for Unity 3.5 and Unity 4+.
    Updated support email details.

    Version 1.4
    Added heart beat sound effects.
    Added flatline sound effect.
    Added “Enable Sound” control.
    Added “Heart Volume” control.

    Version 1.3
    Updated documentation to include mobile build optimisation notes.

    Version 1.2
    Updated documentation.

    Version 1.1
    Added full documentation.
    Added code comments.

    Version 1.0
    Initial release.

    Asset Store Link: "Get the Heart Rate and Beat Monitor".
     
  43. CoderPro

    CoderPro

    Joined:
    Feb 21, 2014
    Posts:
    327
    Could you make a webplayer version to test it ?
     
  44. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    @CoderPro Shouldn't be a problem. I'll put one up somewhere for you.

    Justin
     
  45. Qwak

    Qwak

    Joined:
    Aug 26, 2015
    Posts:
    5
    Is it possible to add it to a UI canvas? And move with the canvas animations?
     
  46. SketchWork

    SketchWork

    Joined:
    Jul 6, 2012
    Posts:
    254
    Hi @Qwak , at present it is an actual 3D asset so doesn't rely on any form of GUI (UGUI, NGUI, EZGUI, etc). I am however looking at adding a way to add the asset to a Unity Canvas for a future version. I'll post here when this work is completed.

    Best regards, Justin.
     
  47. Qwak

    Qwak

    Joined:
    Aug 26, 2015
    Posts:
    5
    Thats great news!
    I'll be waiting.

    Thanks!
     
  48. Zyxil

    Zyxil

    Joined:
    Nov 23, 2009
    Posts:
    111
    Very nice asset!

    I made some tweaks. I added a transparent background sprite behind the HRM.



    I added this to set color directly:

    Code (CSharp):
    1.  
    2.     public Color HeartRateColor = new Color(0f, 1f, 0f, 1f);
    3.     private Color testHeartRateColor = new Color(0f, 0f, 0f, 1f);
    4.  
    5.     void Update()
    6.     {
    7.  
    8. ...
    9.         if (HeartRateColor != testHeartRateColor)
    10.         {
    11.             MainMaterial.SetColor("_TintColor", HeartRateColor);
    12.             testHeartRateColor = HeartRateColor;
    13.         }
    14.     }
    And created a small class to do some custom animation based on bpm.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class HRMAnimate : MonoBehaviour
    5. {
    6.     public AnimationCurve soundAnimationCurve;
    7.     public AnimationCurve redChannelAnimationCurve;
    8.     public AnimationCurve greenChannelAnimationCurve;
    9.  
    10.     private SWP_HeartRateMonitor _hrm;
    11.     private int _testBPM;
    12.     private float _bpmFloatVal = 0f;
    13.  
    14.  
    15.     public void Start()
    16.     {
    17.         _hrm = GetComponent<SWP_HeartRateMonitor>();
    18.  
    19.         if (_hrm == null)
    20.             Debug.LogError("HRM not found");
    21.  
    22.         _hrm.BeatsPerMinute = 60;
    23.     }
    24.  
    25.     public void Update()
    26.     {
    27.         if (_hrm.BeatsPerMinute != _testBPM)
    28.         {
    29.             _testBPM = _hrm.BeatsPerMinute;
    30.             _bpmFloatVal = (float)_testBPM / 240f;
    31.  
    32.             Debug.Log("BPM changed. BPM: " + _testBPM + ", volume: " + soundAnimationCurve.Evaluate(_bpmFloatVal));
    33.  
    34.             _hrm.SoundVolume = soundAnimationCurve.Evaluate(_bpmFloatVal);
    35.  
    36.             _hrm.HeartRateColor = new Color(redChannelAnimationCurve.Evaluate(_bpmFloatVal),
    37.                 greenChannelAnimationCurve.Evaluate(_bpmFloatVal), 0);
    38.         }
    39.     }
    40. }
    41.  
    Some fun stuff to add might be random arrythmias when bpm is > 200.
     
  49. Zyxil

    Zyxil

    Joined:
    Nov 23, 2009
    Posts:
    111
    You need to add this bit to CreateClone for the blip and trail to appear on the correct layer:

    Code (CSharp):
    1.         NewClone.layer = gameObject.layer;
    2.         NewClone.transform.GetChild(0).gameObject.layer = gameObject.layer;
    3.  
     
  50. thanhle

    thanhle

    Joined:
    May 2, 2013
    Posts:
    162
    it not auto scale like Ugui
    How i can do it ?