Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Pocket RPG Framerate Independent Weapon Trails (free)

Discussion in 'Assets and Asset Store' started by Evan-Greenwood, Dec 14, 2011.

  1. Evan-Greenwood

    Evan-Greenwood

    Joined:
    Aug 6, 2008
    Posts:
    98
    I've posted the weapon trail scripts from Pocket RPG on the Asset Store. (I believe they are going through the review process).

    I had a couple requests for these, so I've tried as best I can to bundle them up and stick them up. They are not the easiest trails to use, but they are framerate independent... So even running at a low 30fps they will look smooth.

    I'm not going to be offering support for them (unless there is a glaring bug). But hopefully a couple people will try them, and someone will figure out how to work them, and be able to help anyone who struggles (I would appreciate it).

    There is an example scene with the Blade Master pulling off some sweet moves.

    Please read the "Read me first.txt" and look at the example scene. Because of the way the trails are calculated the scripts have a few dependencies that require setting up in a certain way. It isn't actually that hard if you look through the example and read the comments in the scripts.

    Looking forward to these appearing in some sweet games!

    (Someday I plan to do another RPG and whip together some proper God-Of-War animated weapon trails, but for now these work pretty well)
     
    aibolith likes this.
  2. huxley

    huxley

    Joined:
    Apr 27, 2009
    Posts:
    334
    This is something that I was looking for. Thanks for the community give, Evan!!!
     
  3. Evan-Greenwood

    Evan-Greenwood

    Joined:
    Aug 6, 2008
    Posts:
    98
    First upload got rejected (due to my dodgy splash images)... This one should go through (sorry about the preemptive thread and the delay)
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Cool of you to give back man! many will appreciate it.
     
  5. Ender13

    Ender13

    Joined:
    May 3, 2009
    Posts:
    91
    I'm really looking forward to this. I don't see it on the store yet; are you charging for it?
     
  6. caitlyn

    caitlyn

    Joined:
    Jun 20, 2008
    Posts:
    402
  7. Evan-Greenwood

    Evan-Greenwood

    Joined:
    Aug 6, 2008
    Posts:
    98
    Yay. It's up!

    It's free of course. If you want to support us then encourage your friends to play Pocket RPG :)

    I'm not going to be updating this much (unless there is something embarrassing wrong with it), but I wanted to known for making more packages in the future:

    Is it useable? Has anyone managed to work with it? and if not what should I have done?
     
  8. ficho

    ficho

    Joined:
    Dec 17, 2010
    Posts:
    82
    Thanks Evan so much, is it okay if i use the Blade Master in my own project what is just for myself to learn Unity3D?
     
  9. filiporekhov

    filiporekhov

    Joined:
    Aug 1, 2010
    Posts:
    17
    Sure thing on the Blade Master character, use it as much as you want! Spread the socialism, free stuff for the people :D
     
  10. ficho

    ficho

    Joined:
    Dec 17, 2010
    Posts:
    82
    Thanks :D

    Btw i love Pocket RPG :D
     
  11. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    For the record, I played the living crap out of Pocket RPG. Brilliant game.
     
  12. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    FYI Evan, I am using this perfectly, I should post a pic.


    Thanks a lot!!
     
  13. tr1stan

    tr1stan

    Joined:
    Jan 23, 2009
    Posts:
    150
    This is the best weapon trail effect script ever!

    But I'v also get a bug when the crossfade animation function didn't work properly as Unity's crossfade function. If I want to play the same animation clip again right after the first one with the AnimationController.CrossfadeAnimation function, the second animation will never trigger. If the I insert a different clip in between it will work again.

    Do you have any idea to fix it?
     
    Last edited: Jan 14, 2012
  14. Evan-Greenwood

    Evan-Greenwood

    Joined:
    Aug 6, 2008
    Posts:
    98
    @jrricky I'm glad it's working for you! That looks super sweet! (When will we get to play it?)

    @tr1stan I'm not supporting this. I specifically said as much and what you want is not a little change. Why don't you just use a second similar animation and then just crossfade between the two? That'd be a far easier fix than rebuilding the AnimationCrontroller class.

    Once again, I'm not supporting this, I don't have enough time right now to do my own work, let alone sleep and relax and fix problems people have with a free plugin for Unity.

    I'm sorry if I'm coming off as rude. Please ask the community rather.
     
  15. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    How can I make this work with Mecanim/Anomator?
     
  16. JoelVDV

    JoelVDV

    Joined:
    Oct 26, 2013
    Posts:
    11
    Did anyone get this working with Mecanim well?
    I've got it working (had to call StartTrail(), and : Itterate(Time.time) and UpdateTrail(Time.time, Time.deltaTime) each frame),
    but the whole trail appears to be modified by the transformation.

    Basically trails from a second ago, are being shaken if the sword is shaken... (but it only appears to be sometimes o_O )


    EDIT: Woooow was about to go on a crazy move-from-mecanim-to-this-guys-system spree, which was not at all going to be a small task.

    SOLUTION: Updating the trail from LateUpdate... Essentially the trail mesh is recreated each frame in relation to the world->local matrix. If that matrix changes before it is then rendered, it'll have the weird offsets and rotations I was getting.
     
    Last edited: May 9, 2014
  17. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    has anyone made it work with Mecanim yet?
     
  18. Brockoala

    Brockoala

    Joined:
    Feb 18, 2013
    Posts:
    13
    Has anyone got this working with Animator yet?
    I mean to smooth it out. I don't know how to manually set the current time of the animator (like what he did in FadeInCurrentState) and I can't find the equivalent method to "Sample()" of Animation.
     
    Last edited: Nov 7, 2014
  19. aibolith

    aibolith

    Joined:
    Apr 9, 2017
    Posts:
    9
    Hmm. First of all, big thanks for such a sweet free package, man, available for many years!
    I tried to add a WeaponTrails object with Mesh Renderer and Trail Material and then manually control it by calling Itteration and UpdateMesh without using Animator Controller. I must have set something wrong though as there's absolutely nothing visible in the game. I'll dig into it deeper later and if successful will post a short manual here for people like me who'd like to have some dummy guide :) Thanks again for great work shared.
     
  20. aibolith

    aibolith

    Joined:
    Apr 9, 2017
    Posts:
    9
    OK, so I've got it working but ran into a couple of problems. I'm new at this so it might easily be my bad, but anyway. Main problem is not being able to turn off the emission after the attack is finished. In other words, I couldn't leave old trails to slowly fade away on the screen while my swords would stop to emit new trails. You eithr clear everything, or have emitting objects.
    Secondary problem is that even when I set animationIncrement variable to low values, I still get quite rough lines.
    Also the third problem is that there's probably a better solution overall with using particles or Trail built-in system and I'm just a noob, but other than that here's how I set it working :rolleyes:

    1. I wanted to use trails without using external animation controller code. So I just took everything that controls trails from AnimationController into this script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class TrailEngine : MonoBehaviour {
    6.     protected List<WeaponTrail> trails;
    7.     private float t = 0.033f;
    8.     private float tempT = 0;
    9.     protected float animationIncrement = 0.003f;
    10.  
    11.     private void Awake() {
    12.         trails = new List<WeaponTrail>();
    13.     }
    14.     public void AddTrail(WeaponTrail trail) {
    15.         trails.Add(trail);
    16.         print("added trail: " + trail);
    17.     }
    18.     public void RemoveTrail(WeaponTrail trail) {
    19.         trails.Remove(trail);
    20.     }
    21.  
    22.  
    23.     // Use this for initialization
    24.     void Start() {
    25.     }
    26.  
    27.     // Update is called once per frame
    28.     void LateUpdate() {
    29.         t = Mathf.Clamp(Time.deltaTime, 0, 0.066f);
    30.  
    31.         RunTrails();
    32.     }
    33.  
    34.     void RunTrails() {
    35.         if (t > 0) {
    36.  
    37.             while (tempT < t) {
    38.                 tempT += animationIncrement;
    39.                 for (int j = 0; j < trails.Count; j++) {
    40.                     if (trails[j].time > 0) {
    41.                         trails[j].Itterate(Time.time - t + tempT);
    42.                     }
    43.                     else {
    44.                         trails[j].ClearTrail();
    45.                     }
    46.                 }
    47.             }
    48.  
    49.             tempT -= t;
    50.  
    51.             for (int j = 0; j < trails.Count; j++) {
    52.                 if (trails[j].time > 0) {
    53.                     trails[j].UpdateTrail(Time.time, t);
    54.                 }
    55.             }
    56.         }
    57.     }
    58. }
    59.  
    Then I attached this script to my singleton object GameManager. Then I copy-pasted "LeftTrail" object from Blade Master prefab (you could also manually create object and attach MeshRenderer, WeaponTrail material and script manually, but I wanted to be sure I didn't make a mistake at any point) and added it to the player's weapon.
    After it's set up, I call TrailEngine.AddTrail(WeaponTrail) from my PlayerController script and feed the trail object to it in the void Start().

    So set up is complete. Now when my hero starts attack, I say something like
    Code (CSharp):
    1. leftTrail.SetTime(1f, .5f, 1f);
    and when the attack ends I call
    Code (CSharp):
    1. leftTrail.FadeOut(.3f);
    There's also a WeaponTrail.StartTrail() method but it didn't work for me.

    Hope that it's helpful to whoever find the need to use this in 2017... if I'm not the special snowflake
     
  21. Crouching-Tuna

    Crouching-Tuna

    Joined:
    Apr 4, 2014
    Posts:
    82
    Ok. Gonna bump this because the asset is awesome and free, but doesn't support mecanim.
    I managed to make it work with Animator.Update(animationIncrement). Quite simple, really.
    At the end of the loop, I did Update(-t). Without it, well, it'll make the animation that much faster because Update literally fastforwards it during the loop.
    But with the negative Update, I'm getting this spammy error whenever the Animator transitions:

    Code (CSharp):
    1. Assertion failed: Invalid time range for Transition exit time condition
    But it still runs no problem. I think if current state is less than t, it'll shoot that error, I assume it'd try to reverse update to a previous state(which is invalid?), but I'm not sure if it's actually messing anything up.
    Anyone have a suggestion how to revert back the animator back that certain amount?
    Some commented parts are some other things I tried but doesn't seem to make much difference.

    Code (CSharp):
    1. if(t > 0)
    2.         {
    3.             var animInfo = myAnim.GetCurrentAnimatorStateInfo(0);
    4.             float curAnimTime = (animInfo.normalizedTime % 1) * animInfo.length;
    5.             myAnim.enabled = false;
    6.             //myAnim.anim
    7.             while(tempT < t)
    8.             {
    9.                 tempT += animationIncrement;
    10.  
    11.                 myAnim.Update(animationIncrement);
    12.  
    13.                 for(int j = 0; j < trails.Count; j++)
    14.                 {
    15.                     if(trails[j].time > 0)
    16.                     {
    17.                         trails[j].Itterate(Time.time - t + tempT);
    18.                     } else
    19.                     {
    20.                         trails[j].ClearTrail();
    21.                     }
    22.                 }
    23.             }
    24.             //if(curAnimTime > t)
    25.                 myAnim.Update(-t);
    26.             myAnim.enabled = true;
    27.             tempT -= t;
    28.  
    29.             for(int j = 0; j < trails.Count; j++)
    30.             {
    31.                 if(trails[j].time > 0)
    32.                 {
    33.                     trails[j].UpdateTrail(Time.time, t);
    34.                 }
    35.             }
    36.         }