Hello,
Couldn't see a dedicated Footstepper Board so I've written here. Hope it is fine.

I've successfully added Footstepper for my characters in 2D mode. Now I'd like use it on my projectiles.
I've look at the Demo scene. Other than tha player character, the "CratePink" object shows how to play audio using raycast2D and Footstep Materials.
So I set up my projectile looking at that and called Land(-1) on its Footstepper component when Unity calls OnTriggerEnter2D.
but I'm getting this
Coroutine couldn't be started because the the game object '_machineGunProjectile-0' is inactive!
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
GamingIsLove.Footsteps.Footstepper:PlayFootstep(Transform, Single, FootstepType) (at Assets/Footstepper/Scripts/Footstepper.cs:387)
GamingIsLove.Footsteps.Footstepper:Land(Int32) (at Assets/Footstepper/Scripts/Footstepper.cs:843)
CallFootstepperonCollision:OnTriggerEnter2D(Collider2D) (at Assets/CallFootstepperonCollision.cs:16)

It is probably because projectiles are being pooled.
So I tried footstepper.SetGrounded(true);
It seems to work but not all the projectile hits register.
I don't know how to approach this.
I don't think I can change the pooled projectiles.
So my question is:
- How to setup a projectile to play Footstepper when its is pooled?
-Is it OK to use SetGrounded on such a case?
-Is it an overkill to use "Footstepper" component for a projectile? Would it be better to make a new component dedicated for fast moving physics objects?

Thanks for the help.
  • Yep, it's fine - that's what the general support section was added for :)

    I haven't tested using Footstepper for projectile collision effects, I think the main issue will be that the projectile will be disabled/destroyed right after, which stops playing the audio clip on it and interferes with the prefab's coroutine (which is responsible for removing it after the defined time).
    Pooling itself shouldn't really be an issue, as it doesn't matter if it's destroyed or just disabled.

    The best solution would be to make sure the projectile is kept enabled/alive long enough for the audio clip and prefab to be done. So maybe instead of just playing the footstep and removing the projectile, use a coroutine that plays the footstep, waits for a second and removes the projectile afterwards.

    Something like this:
    public IEnumerator ProjectileHit()
    {
    footstepper.Land(-1);
    yield return new WaitForSeconds(1);
    gameObject.SetActive(false);
    }
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks for the reply GiL

    Looking further (I understand from the raycast 2D gizmo) Footstepper raycasts down in world space and I couldn't find a way to rotate it to align with my projectile.

    This might be the cause of Footstepper not firing every time. It seems to work more often on ground but less on walls.

    I tried rotating the raycast by using "in foot space" but couldn't achieve it.
  • Well, you could directly get the footstep effect from the object that was hit instead:
    FootstepSource footstepSource = hitGameObject.transform.GetComponentInParent<FootstepSource>();
    if(footstepSource != null)
    {
    FootstepEffect effect = footstepSource.GetFootstepAt(hitPosition, "effectTag");
    }

    hitGameObject is the game object that was hit (obviously :D), hitPosition the position (e.g. from the collision), the text is the effect tag that should be used (e.g. if you've set up tag effects for the bullets).

    There's currently no function to play that effect via the footstepper, but you can just copy the code (or write your own function in the footstepper) to do that. The code for playing the effect can be found in the Footstepper class in the PlayFootstep function (line 372-391).
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks again,
    I'm not sure I was able to show the problem clearly.

    https://dropbox.com/s/ksgdpaup8hfmj6o/Annotation740.jpg?dl=0

    My projectile is looking right in world space. Footstepper raycasts down (red thin line) I want to rotate it so it is aligned with the projectile (blue line)

    I don't think it is registering as a raycast hit because of this rotation.

    I couldn't put an image into the thread so added a link. hope it is OK.
  • edited February 13
    Or do you mean make your own raycasting in a script and get the FootstepEffect that way without using Footstepper component?
    It just seems that I was able to rotate the raycasting by using a "Feet Transform" and In Foot space checkbox.

    OK I'll try to copy your raycast code and try that way
    Post edited by gurayg on
  • No, I meant without raycasting at all - your projectile is already colliding with something, so you'd just need to get the footstep effect from that object via the code I posted above, e.g. in an OnCollisionEnter2D function in your projectile's script.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • gamingislove said:
    I haven't tested using Footstepper for projectile collision effects, I think the main issue will be that the projectile will be disabled/destroyed right after, which stops playing the audio clip on it and interferes with the prefab's coroutine (which is responsible for removing it after the defined time).
    Why not just spawn an empty on collision with an attached component?
  • Well:)
    The asset library I'm using works with OnTriggerEnter2D for projectiles and I couldn't find how it is dealing with pooling in terms of disabling a GO. So what I did was;

    -I made a new component and add it to my Footstepper manager GO so it stays enabled on runtime.
    -I made a public method with projectile' GO and colliding object' GO as its parameters.
    -I call that method when OnTriggerEnter2D is called on the projectile script. I'm using projectile's transform as hitPosition. Also sending the colliding object makes it possible to do the Footstepper stuff.

    This seems to work but I'm not sure if I'll bump into an issue later on.
  • There's actually the Footstep Trigger component to start footsteps via trigger events :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.