Forum rules - please read before posting.

Dust puffs from footsteps

edited March 8 in Technical Q&A

A good day. I'd love to please get some help with something - been trying to get little puffs of smoke to kick up when the player character moves. I'm making a 2D game using Sprites Simple for the player character. I've tried unsuccessfully with Animation Events, maybe it's a limitation of Sprites Simple but when I add an event to a keyframe of a character animation eg 'walk', the only option I get in the inspector is 'function' and 'follow sorting map' as an option, which I think doesn't help me much. I also don't see anything in AC's 'Events Editor' that might work, I tried 'Character > Point and Click' but it doesn't really work, sometimes particles turn on and no way to switch it off. The main issue I'm having is not knowing how to turn particles on and off by 'character moving speed' and I'd also ideally like particles to not follow the character as he walks, ie the dust should kick up and not move left and right, just up. I also tried following this but couldn't get it to work: https://adventurecreator.org/forum/discussion/14503/particles-whilst-walking

Rough idea:

Similar to how many other games do it, eg here's 'Duck Detective' kicking up little puffs of smoke as he moves.

Comments

  • I got Claude.ai to write me a script:
    https://pastebin.com/VXnBSveU
    which surprisingly does kind of work (I don't really understand it, but it works), made a separate Particle system then attached this script to the player and dragged the particle system into the field. It's not perfect (the puffs appear at the start of a scene and then stop), but yeh, this is the kind of thing I'm aiming for I guess:

  • edited March 10

    The Claude script is actually working pretty well for me. Tweaked it so I only get the particles (which is a basic sprite animation) playing when the player moves over a certain speed. I don't think what I ended up with needed to be particles, but anyways. Works for now.
    [Actually, maybe not. Getting very unusual computer freezes and crashes, might be related to this, not sure]

  • Having mixed results with AI making scripts. Is there a simple/performant way to do this, please?

    I'm kind of getting there with AI slowly but there always seems to be some caveat downside.
    Just want a short couple-frame animation to play when character runs, to be able to dial in speed of the animation and the space between them (and ideally separate effects when character walks or runs.)

  • Use Unity's Profiler, with Deep Profile enabled, to learn the source of any performance spikes in the scene.

    If you're looking for a simple sprite animation, switching to an Animator prefab that just plays a simple sprite animation may be preferable. Rather than playing particles, just spawn in an instance of the prefab.

  • edited March 11

    Thanks Chris, will try the animator prefab method.
    Ignorant question - what’s a good way to spawn in that prefab, please?
    I’m thinking maybe I could add animation events for each step, and then somehow (maybe with custom scripting) spawn in a prefab each time an event is triggered, and maybe destroy it at the end too so they don’t stack and take up memory. Or make sure only like 3 prefabs can be shown at any time with a pool or something.

  • Chris will undoubtedly have a better solution than me but if I want something to not be visible, I change the asset to use a material that is invisible. Would that be useful?
  • Thanks for the comment! It’s a good idea, I also sometimes use a blank png / blank animation to essentially get rid of something. My concern is more that the character walks around a scene for 30 seconds and spawns like, 1000 little dust animation prefabs.
    I’m not super au fait with prefabs, so wouldn’t know how to destroy them. I know in principle there’s a way to have a limited ‘pool’ of them where instances keep getting reused (I saw Corgi Engine or Top Down Engine uses a pool for bullet sprites). But yeh, just want to make sure it’s somewhat performant.

  • Ah right, I haven't done anything like that yet, personally I'd just keep it simple and have the dust marks be a part of the running animation and call it a day, lol.
  • edited March 12

    Yes, animation events is the way to go if you want to spawn them in.

    Something like this, attached to the Animator's GameObject, should do it:

    using UnityEngine;
    
    public class PrefabSpawner : MonoBehaviour
    {
    
        public GameObject prefabToSpawn;
        public float lifeTime = 2f;
    
        public void SpawnPrefab ()
        {
            var newOb = Instantiate (prefabToSpawn);
            newOb.transform.position = transform.position;
            Destroy (newOb, lifeTime);
        }
    
    }
    

    This'll spawn a prefab in when the "SpawnPrefab" event is triggered, and remove it some time later.

  • Hi Chris, super, thank you.
    May I ask please if there a way to make it so the dust puffs only trigger when the character's running? I don't have a unique running animation, the character just moves quicker.

  • using UnityEngine;
    using AC;
    
    public class PrefabSpawner : MonoBehaviour
    {
    
        public GameObject prefabToSpawn;
        public float lifeTime = 2f;
        public Char acCharacter;
    
        public void SpawnPrefab ()
        {
            if (!acCharacter.isRunning) return;
    
            var newOb = Instantiate (prefabToSpawn);
            newOb.transform.position = transform.position;
            Destroy (newOb, lifeTime);
        }
    
    }
    
  • edited March 13

    Thanks Chris, that does the job really nicely. I asked Claude to tweak it a bit for me so I could have different PreFab dust animations for both running and walking, and also added an offset to correctly place it:

    using UnityEngine;
    using AC;
    
    public class PrefabSpawner : MonoBehaviour
    {
        public GameObject runningPrefab;
        public GameObject walkingPrefab;
        public float lifeTime = 2f;
        public Char acCharacter;
        public Vector3 positionOffset = new Vector3(0, 0.1f, 0);
    
        public void SpawnPrefab()
        {
            GameObject prefabToSpawn;
    
            if (acCharacter.isRunning)
            {
                // Character is running
                prefabToSpawn = runningPrefab;
            }
            else
            {
                // Character is not running (assume walking)
                // You might want additional checks here if the character could be stationary
                prefabToSpawn = walkingPrefab;
            }
    
            // Only spawn if we have a valid prefab for this movement state
            if (prefabToSpawn != null)
            {
                var newOb = Instantiate(prefabToSpawn);
                newOb.transform.position = transform.position + positionOffset;
                Destroy(newOb, lifeTime);
            }
        }
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.