energy shield hit-effect

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 :slight_smile:

this is the shader

and this is the script:

function OnCollisionEnter(collision : Collision) {
		for (var contact : ContactPoint in collision.contacts) {
			Debug.Log(contact.point);
			renderer.sharedMaterial.SetVector("_Position", contact.point); //transform.InverseTransformPoint(contact.point));
		}
	}

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

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:

function Update(){
	renderer.sharedMaterial.SetVector("_Position", transform.FindChild("hitpoint").position);
}
	
function OnCollisionEnter(collision : Collision) {
		for (var contact : ContactPoint in collision.contacts) {
			transform.FindChild("hitpoint").position = contact.point;
		}
}

It works just fine, but I wonder if there is a better way to do this.

I have a forcefield effect in my “aubergines shader pack” which accepts 3 hits per object(can add up to 8 hits).

So, if you are not happy with the current solution, there is another.

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 :slight_smile: it works now great \o/. If you could post it to the >shader< as answer, I would gladly accept it.

Well, he asked;

So, i mentioned. Did i do something wrong here that you are harsh on me, or is it something else?