How to I measure the total distances between chain links?

0 favourites
  • 5 posts
From the Asset Store
Cue in the war drums and battle cadences with Total War Game Music Loops!
  • Hi guys. I'm attempting to measure the distances between chain links made up of a single sprite.

    I am using R0j0s verlet motion as a base cp3 file.

    I made a loop in the c3p as visible here to add up distances.

    Theoretically the displayed summation of distances should always be no less than the assigned distance in between times sprite count which in this case is 8*31 but in execution, in my loop at least, I seem to be ending up with values less than that moving my main character sprite around. I seem to only be measuring the distances between the first the last link.

    file: del

    I need help pointing out what I did wrong and how I may fix this loop. Thanks.

    EDIT: Also is there a way I may store the summation variable so I can create a set of events like :

    if summation > theoretical max = do this..

    with the nature of the SumDistance variable being in a constant state of flux inside the loop how would that work?

  • Can't open your file. I think it's not publicly shared?

    Probably that wait is causing problems, but I can't really follow it.

    Anyways this should measure the total length between multiple instances of sprites making up the chain.

    var totalLength=0;
    
    for "" 0 to p.count-1
    -- loopindex = 0
    -- -- set totalLength to 0
    -- else
    -- -- add distance(p(loopindex-1).x,p(loopindex-1).y,p(loopindex).x,p(loopindex).y) to totalLength
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Can't open your file. I think it's not publicly shared?

    Probably that wait is causing problems, but I can't really follow it.

    Anyways this should measure the total length between multiple instances of sprites making up the chain.

    var totalLength=0;
    
    for "" 0 to p.count-1
    -- loopindex = 0
    -- -- set totalLength to 0
    -- else
    -- -- add distance(p(loopindex-1).x,p(loopindex-1).y,p(loopindex).x,p(loopindex).y) to totalLength

    hi thank you for your reply.

    I fixed the link.

    I also applied your suggested loop but for some reason I'm getting a summation value of 0. With the link accessible now maybe you could figure out what's wrong with my code

  • Your code wasn't correct. The total length is zero because you set it to zero when loopindex=p.count-1 aka at the last instance. It should be loopindex=0 like in the pseudo code. Also you don't need to use abs() with distance because distance is already always positive, but that has no effect.

    The verlet rope physics doesn't work too well when wrapping around small obstacles as you noted in the layout. It can be improved by decreasing the distance between links and/or running the physics with multiple smaller timesteps, but it still can fail. I think it could be improved by doing collision detection/response between the obstacles and the lines between links, but that's not a simple to solve with the circle vs sdf collision detection used.

  • Your code wasn't correct. The total length is zero because you set it to zero when loopindex=p.count-1 aka at the last instance. It should be loopindex=0 like in the pseudo code. Also you don't need to use abs() with distance because distance is already always positive, but that has no effect.

    The verlet rope physics doesn't work too well when wrapping around small obstacles as you noted in the layout. It can be improved by decreasing the distance between links and/or running the physics with multiple smaller timesteps, but it still can fail. I think it could be improved by doing collision detection/response between the obstacles and the lines between links, but that's not a simple to solve with the circle vs sdf collision detection used.

    Alright. I'll be experimenting with your variables further to get the results I want.

    Thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)