Search Unity

energy shield hit-effect

Discussion in 'Shaders' started by vargata, Dec 30, 2013.

  1. vargata

    vargata

    Joined:
    Nov 26, 2013
    Posts:
    120
    Hi ppl,

    I would need some help as got struct with my shader. It's on unity answers, I bring it to the shader forum to have a bit more chance to find the right help :)

    this is the shader

    and this is the script:
    Code (csharp):
    1. function OnCollisionEnter(collision : Collision) {
    2.         for (var contact : ContactPoint in collision.contacts) {
    3.             Debug.Log(contact.point);
    4.             renderer.sharedMaterial.SetVector("_Position", contact.point); //transform.InverseTransformPoint(contact.point));
    5.         }
    6.     }
    it's cool as long as my object doesnt move, but how to stick the effect to the object instead of the worldspace? any workaround?

    Thanks in advance
     
  2. vargata

    vargata

    Joined:
    Nov 26, 2013
    Posts:
    120
    well, as an ugly workaround i've attached an empty gameobject to the shield and gave it a name "hitpoint" and modified my script to:

    Code (csharp):
    1. function Update(){
    2.     renderer.sharedMaterial.SetVector("_Position", transform.FindChild("hitpoint").position);
    3. }
    4.    
    5. function OnCollisionEnter(collision : Collision) {
    6.         for (var contact : ContactPoint in collision.contacts) {
    7.             transform.FindChild("hitpoint").position = contact.point;
    8.         }
    9. }
    It works just fine, but I wonder if there is a better way to do this.
     
  3. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    I have a forcefield effect in my "aubergines shader pack" which accepts 3 hits per object(can add up to 8 hits).
     
  4. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    So, if you are not happy with the current solution, there is another.
     
  5. vargata

    vargata

    Joined:
    Nov 26, 2013
    Posts:
    120
    Guys, don't start an argument. Actually meh11 is very much right, if I wanna buy one, I could find tons of shaders in the assetstore. I do it to learn and I'm not gonna pay $50 for every little solution (which is actually a great help if I can learn from it).

    @meh11, Thanx a lot, I was working from those examples and the solution was right in my face, just haven't found it :) it works now great \o/. If you could post it to the >shader< as answer, I would gladly accept it.
     
  6. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    Well, he asked;
    So, i mentioned. Did i do something wrong here that you are harsh on me, or is it something else?