- Home /
Trail renderer with damage
I have seen some topics on Trail renderer collision, but none of it made sense to me. Do you use a script? Or is there some item on the Unity3d menui can use, I thank you in advance.
Unity3d - regular
Scripting exp - moderate
Answer by Chris D · Jul 20, 2011 at 05:32 PM
I'm going to go ahead with the assumption that you are referring to this thread in terms of what you didn't understand. The idea proposed there is to get the points at which the trail renderer is creating it's particles and doing a raycast between them.
Looking at the documentation, it doesn't seem that it's easy to get all the info you need from the object itself (you can set the minimum vertex distance, but I'm not sure how or if you can access that list of points) so I propose a different solution: fake it.
Make a series of small gameObjects with colliders (but no mesh renderer) inside the trail and just use unity's regular features.
Answer by JUnityer · Jul 20, 2011 at 05:28 PM
I don't know how to make the trail renderer itself collide, but I have a suggestion how to do it if you are trying to make a bullet or anything similar that's supposed to make damage to enemies or something...
I would make an invisible game object, for example, a small sphere (disable it's mesh renderer but not the collider). Then add a trail renderer to it, adjust it's settings for your liking, and make it a prefab (or whatever you need it to)
That would make a trail renderer that can collide! Hope you understand what I mean...
beat me to it :D
I'll leave my answer below as reference to the docs, but yes; do this.
$$anonymous$$ake a small sphere every so often, it makes sense to a point, but if you had 3 object with trail, wouldn't that bog down the game alot?
To a point. It's going to depend on how frequently you want to create a new object there, how many you want to have available at once (how long the trail will be), etc. It's just a matter of balancing the behaviour you want with the performance you need.
In that case I would probably do it using raycasting, but if the trails aren't supposed to be very long or that they are destroyed over time, the gameobjects should manage well. What are you going to use this for, by the way? something like Tron, perhaps?