Trail effect with emitter?

I want to try this first then eventually I’ll go on the hard.

So you can give me a tip?

I have p1 and p2. Then I derive the distance between the two points:

 local xFactor = p2.x - p1.x local yFactor = p2.y - p1.y local dist = math.sqrt( (xFactor\*xFactor) + (yFactor\*yFactor) )

and the number of “extra” pieces

local extraPiece = math.round(dist/mySpace)

now how to calculate a possible point p3,p4,… at a X distance from p1?

You almost got it there dude, here is a piece of code that is working as you want:

--constant you can modify local SPEED\_BALL = 10 local RADIUS\_BALL = 20 local STEP = 3 local TRAIL\_FADE\_DURATION = 500 local ball = display.newCircle(0, 0, RADIUS\_BALL) ball.vx = SPEED\_BALL ball.vy = SPEED\_BALL ball:setFillColor(1,0,0) local onUpdate = function(e) local A = {x = ball.x, y = ball.y}--previous position --move the ball ball.x = ball.x + ball.vx ball.y = ball.y + ball.vy local B = {x = ball.x, y = ball.y}--new position --get the distance local dx = B.x - A.x local dy = B.y - A.y local dist = math.sqrt(dx\*dx + dy\*dy) --draw trail particles local nbIterations = math.floor(dist / STEP) for i=0, nbIterations do local xx = A.x + i \* STEP \* dx/dist local yy = A.y + i \* STEP \* dy/dist local trailParticle = display.newCircle(xx, yy, RADIUS\_BALL) transition.to(trailParticle, {time = TRAIL\_FADE\_DURATION, alpha = 0, onComplete = function() trailParticle:removeSelf() end}) end --bounce on arena bounds if ball.x \> 320 then ball.x = 320 ball.vx = -ball.vx end if ball.x \< 0 then ball.x = 0 ball.vx = -ball.vx end if ball.y \> 480 then ball.y = 480 ball.vy = -ball.vy end if ball.y \< 0 then ball.y = 0 ball.vy = -ball.vy end --display ball over trail ball:toFront() end Runtime:addEventListener("enterFrame", onUpdate)

@david.ciaudo

Thank you so much what I needed to find p3!!

I’m going to make some changes to make the effect more beautiful by calculating also alpha ect as said @roaminggamer in past

Anyway now I should have everything I need to do it myself!

I’d love if someone made a plugin for this. Not with display.newObjects but actually doing it properly. I know I’d pay good money for that :slight_smile:

i knew if anyone had it, it would be you! :slight_smile:

take this fwiw, not meant to sound nitpicky…

if you’re interpolating the trail positions separately from the ball’s position, you’re likely to get weird results whenever the ball bounces off a wall (because the shadows interpolate assuming full vx/vy were applied, but wall prevented that).  to solve: interpolate ball’s position in smaller dt’s, creating trails as you go.

when bouncing (aka reflecting) off walls you shouldn’t clamp position, because you’ll lose velocity.  (player will see it as a “stutter”)  work it out in your head:  say x=473, xmax=480, vx=10.  after a full time step x would be 483, but reflects back to 477, so that all vx=10 is accounted for.  pseuducode is “if (x > xmax) then x=xmax-(x-xmax) end” and similarly for other walls.

hth

@naveen_pcs I might have a go at it, though some ideas will need time to stew. Also it’s not clear if the curve logic (most likely curated from those modules linked earlier) should be included or a separate plugin it would build on. Anyhow, I’ve got a list to whittle down first, things like Clipper

@davebollinger…and it sounded like you might have been alluding to Cosmin’s wrapper in Luapower , which was where I first discovered it. I think I’ll have to adapt that sample.  :) Originally I meant to hew more closely to his API, but there seems to have been some drift since then in Clipper itself. I should probably send stuff like this along to LuaRocks too, at some point.

@StarCrunch - i thought i’d seen one, but couldn’t remember, that may have been it.

aside:  tinkered briefly cleaning up some personal code, still pretty special-use, might eventually?  be suitable for market

2QDs8Lz.png

So after a few days, I managed to get a really decent effect.

But of course it works fine only if the object does not make tight turns. 

I’m still far from what I really thought

But I’m seeing some really wonderful things here!

I would also like to see how it will be once your project is finished @StarCrunch  :smiley:

A follow-up about the Clipper plugin mentioned above. I’ve been putting together some examples for it and am looking to submit in another week or so. It will probably land along with msquares (whose own samples I’m meaning to spruce up) around the same time.

Sample so far, with maybe two or three more ideas pending:

[media]https://www.youtube.com/watch?v=mpym60pSfks[/media]

It looks really great! I try it now, thank you very much.

and sorry for being late

@Sig.g1 I haven’t submitted yet, but might over the weekend.  (Lately I’ve managed to distract myself binding this and this.) You should be able to see the sample’s code through the Clipper link above, though. There were a couple other cases I planned to add (Minkowski difference; Luapower-ish all-in-one scene), but it’s probably ready enough now.

The “Polygon offset” scene shown in the last few seconds of the video, adapted from an example in Clipper’s docs, demonstrates the capability  @davebollinger mentioned earlier.

I realized later, at the beginning I just wanted to hurry up and try :rolleyes:

So I take a look at clipper link. I look forward to the “full” launch!

@Sig.g1 Update on this: it’s now out. Let me know if you try it and have any questions.

[quote name=“davebollinger” post=“383840” timestamp=“1528914020”]@StarCrunch - i thought i’d seen one, but couldn’t remember, that may have been it.   aside:  tinkered briefly cleaning up some personal code, still pretty special-use, might eventually? be suitable for market   2QDs8Lz.png[/quote] This is exactly the kind of thing I’m looking for! I really hope you consider making this into a plug-in.