The nice thing is that, since the package actually includes the source, it’s fairly easy to add those types of features on your own, if you need them now.
I really appreciate how simple and streamlined it is while producing some very nice and heavily customizable trails.
The only thing I’d like to improve that I can’t figure out… is how to get the trail to be more flush with the start/end line so that there’s less/no gap between the weapon and the trail.
I have a little work around that I managed to get together. It might not work for everyone, though.
Graphics.DrawMesh draws into the Default sorting layer… so, if you want to place anything that you want to be able to sort above/below the weapon trail dynamically into that layer (i.e. a player where you might have overhead chops vs sweeping slashes) you can get them meshes to render above or below the objects in that layer based on the z-axis (assuming you’re using xy as your 2d plane.
However, there’s still one annoying issue. For some reason, the mesh vertexes themselves aren’t taken into account when checking distance layering with sprites. If you use Graphics.DrawMesh and pass an actual position in, that does work. So, I went through and changed all the places where you set a value in the m_snapshotList and replaced the z-axis for the PointStart/End with a 0. Then, I pass a new Vector3(0, 0, _gameObject.Transform.position.z) into the Graphics.DrawMesh.
This will effectively work the same way (at least in 2d it does), except that it will layer correctly, allowing for dynamic animations that change the z-axis positioning at will to change where the mesh is in the default layer
This seems to work, but I’d rather waiting for the official support for drawing mesh with sorting layer.
Actually I’ve just submitted a new version which gives “Use With 2D Sprite” option to create mesh object to render the trail.
Thank you for kindly making and releasing this code to the public. It works so well and it’s really really good.
I would like to remind you of one last thing. If I’m not mistaken, even if you do use a mesh object to render the trail, the way you were doing it in the previous version still had the issue of not ordering the mesh correctly WITH IN a layer. It did grant the ability to set the sortingLayer, which was very nice… but it still didn’t properly set the render order with in the layer.
The reason this would happen is due to the fact that your actual GameObject’s position is what’s used to determine the order in the layer with regards to 2d render sorting. With your previous version, your GameObject that held the mesh was actually locked into one position at the origin, I believe. Then your mesh was generated in a similar way to how it is now… and the local position relative to that object was how it was rendered.
Similarly, when you use Graphics.DrawMesh, it treats the matrix/position as the “GameObject” position when determining render order.
I have two possible solutions, one is more robust but requires more math:
This one requires more work/math to get it to work correctly. Instead of creating a new GameObject which will sit at the origin point and never move so that it can house a Mesh component, generate the mesh straight into the GameObject with the XWeaponTrail component. Then use the LocalPosition of the Start/End points to generate your mesh trail instead of their global positions. Now the mesh being rendered has a physical location that lines up with the containing GameObject and it’s render order will be based on the XWeaponTrail’s gameObject’s position, instead of always staying at the origin.
This one requires a bit more work because your whole system is based around assuming that you’re working from the origin.
You can make it so that when you’re in 2D mode, in addition to using a mesh component instead of Graphics.DrawMesh, you choose which plane you’re playing your 2d game in (XY, XZ, YZ). Then, based on that, you use the axis which is prependicular to that plane and make it so that the mesh is always generated with a 0 on that plane for all vectors and you make sure that the object that contains the mesh tracks the position of the XWeaponTrail along that axis.
This will allow the user to control the render order within a sorting layer along that axis.
This is basically what I did with the Graphics.DrawMesh to get it working (except that even with this tweak, it’s still stuck in the Default layer).
I’m pretty sure that even when you use a mesh object, it still has this issue.
One of my sword animations plays too quickly and the path of the x-weapon trail gets messed up. Is there any way to fix this? I’ve tried raising the FPS and the granularity but neither seem to help.
based on the description, maybe you didn’t deactivate the trail when the animation finished?
FAQ: Is it possible to stop the weapon trails when the attack animation is not playing?
Yes, you need to call the API in the XWeaponTrail.cs:
call Activate() when you want to turn the trail on.
call Deactivate() when you want to turn the trail off.
Please refer the XWeaponTrailDemo.cs to learn more.
Sorry for this inconvenient, I don’t keep an older version of xweapontrail.
If you really need it you can copy it from unity 5.5 to unity 5.4.2, and re-assign the script there should be no problem.
Hey great plugin :). I’m trying to slow down time on the trail effect. In my game which I have a time multiplier which I multiply x Time.Deltatime to get the slowing effect rather than using unity’s native timescale option.
I tried this approach on this plugin (I only found 2 lines using deltatime) and it was unsuccessful. Is there a way to get the desired effect? Thanks!
Since I started using pooled prefabs for my weapons, I’m having a problem with X-Weapon Trail.
Here is what is happening:
When I start the game, my weapons are not equipped but they are spawned as deactivated prefabs at world space position 0,0,0. (This is the default use case of PoolManager). I Activate and Deactivate the weapon trails per the API when I swing my weapon. When I equip my weapons, they are activated and attached to the player. Upon the very first sword swing, after my player is equipped with weapon in hand, when I first Activate the weapon Trail, the weapon Trail flies/spreads from world space position 0,0,0 to the weapon local position. After that very first activation, the weapon trails are all correct and start at the local space weapon position.
I have my weapon trails childed to my weapon mesh gameobject exactly as you do in your demo scene.
It’s only on the very first activation of the weapon trail that the trail flies across the screen from world space location 0,0,0 to my player’s local position and the local position of the weapon. This is because that’s where my weapons start as deactivated pooled prefabs. For some reason X-Weapon Trail is grabbing that first world space location and using that as it’s beginning draw location and it only occurs the first time you swing the sword.
My guess is you don’t see this in your demo because your weapons start already attached to your player and you are not using weapons that are pooled prefabs.
Any help would be appreciated. Also I am using the current version of Unity and X-Weapon Trail.
I think I solved my own problem. In the start method of my weapons, I call Init() and Deactivate() on all of my weapon trails. That seemed to fix my problem.
Hi, Great assets dev^^
Can I remove a trail at any timing?
1.Combo1 Activate
2.Combo1 Deactivate
3.Move
4.Combo1 Activate <= I want to remove previous Combo1 trail
The trail that last state show again when I activate trail.
This is a little troublesome in my project.
You can easily check by calling Stop method before playing animation at XWeaponTrailDemo.cs.