Lerp between Localspace & Worldspace positions

0 like 0 dislike
67 views

Hi!

I'm trying to get a particle with an infinite life to follow the object it's attached to, but fall behind and catch back up.

I have a setup similar to Julien's here, but I know it's not intended to bring the particle back.
https://answers.popcornfx.com/792/local-and-world-space?show=792#q792.
I'm using an attribute (r) to control when it lags behind similar to DetachLifeRatio.

using
lerp(HandPos, FreePos, r);
instead of
select(HandPos, FreePos, LifeRatio > DetachLifeRatio);

If I slide between the two, I can get the particle to fall to worldspace, but come back to localspace with an offset of where it was in worldspace...  How can I lerp it between this offset and 0 in localspace over a specified amount of time?

https://imgur.com/Q0IIXiZ

Also, checking the InheritedVelocity would be much better for determining when the particle should lag behind. If InheritedVelocity > threshold, move to worldspace. Once it falls back under the threshold, lerp back to localspace. Are we able to check InheritedVelocity?

Thank you!

edit: I'm also open to suggestions on better ways of doing this altogether

asked Jan 9 by gtapperdesign (1,020 points)

1 Answer

0 like 0 dislike

Hey Greg,

looking at the gif, it seems as if the local position gets lost once it lerps to worldspace.

For this to work you need to keep the local position at all times.

So, if you're doing this:

HandPos = lerp(HandPos, FreePos, r);

It's not going to work once 'HandPos' has started drifting away, because you've then lost the local position.

You need to keep "HandPos" untouched by the lerp, and always keep it local.

You can debug this by having two particle renderers:

one that uses the real position you want, that gets lerped, etc.

and one that uses "HandPos" that follows the hand in localspace.

the effect should clearly draw two sprites, one that stays stuck on the model, no matter how many times you play with that attribute, and the other one that goes back and forth between local and world.

The localspace evolver doesn't apply the velocity of the parent game object.
So you'd have to expose a float3 attribute, and set it to the ingame velocity.

you can do mesh.sampleVelocity(pCoords) on a mesh attribute sampler, and get the surface velocity at that location on the surface, but it's the skinned mesh velocity without the game-object velocity applied either.(someone working with the Unity plugin please correct me if I'm wrong, as this is game-engine dependent AFAIK)

If that doesn't help, I'll need to see the actual effect to help you troubleshoot it

answered Jan 10 by Julien (31,190 points)
I have Position = lerp(HandPos, FreePos, r); not HandPos= . I thought setting HandPos = 0 in localspace would give me what I wanted because I'm lerping to the origin of that localspace evolver, but it always brings it back to the worldspace origin even though it's in Localspace. If it's set to FreePos, it's at least noticeably in localspace... with an offset.

I'm not using Velocity like the other question since I want full control between the two positions. I'll only be checking the inheritedVel for lerping. Here's my setup.

Script 1:
FreePos = Position;

Localspace Script 2:
TmpPos = Position;
HandPos = FreePos;

Script 3:
FreePos = Position;
Position = TmpPos;   
Position = lerp(HandPos, FreePos,r);

I'll send a simplified version your way.
...