Randomly spawning a new entity causes it to glitch at origin for a split second

Hi, I’m creating a mini-game based on pokemon where a pikachu has to dodge randomly generated pokeballs. The new pokeballs are spawned at the top of a ramp. The random spawning is working, however for a split second there is a flickering image of a pokeball at (0,0,0), which I’m assuming is because that is where all new entities start? I have tried a couple different things to try to get rid of this flickering behavior but no luck. If anybody has a solution I would appreciate it greatly! here is the link to my game: PlayCanvas | HTML5 Game Engine

HI @SM2209 and welcome,

Normally I would have thought doing newEntity.rigidbody.teleport(position) instead of newEntity.setPosition(position) would have worked, but that’s not the case here.

The temp fix I’ve found is to set the rigidbody type initially to kinematic in your PokeBallEntity entity:

And then add this line at the bottom of your _spawnPokeBall method:

newEntity.rigidbody.type = pc.BODYTYPE_DYNAMIC;

Thank you! I did try what you suggested but it seems like initially setting it to kinematic stops the pokeballs from rolling at the start, any idea why that may be?

So, the balls needs to be dynamic to roll using physics.

My trick, setting them to kinematic, is only good for the instant you are spawning them. As soon as that happens and the position is set, they should be set to dynamic.

Still I’m puzzled why that happens in this case, but the project is too big to fully debug, sorry.

ah, no problem thank you anyways!

I’m hitting a similar issue in another project with a particle effect

So far the workaround I’ve found is to have it disabled in the template

Create the instance with instantiate and then enable it on the next frame

            var effect = this.particleEffects[i].resource.instantiate();
            setTimeout(() => {
                effect.enabled = true;

For now I was able to hide the issue by simply moving the arena up which is not ideal so I’ll give this a try!