[SOLVED]How do I constrict/expand?

0 favourites
  • 11 posts
  • Hello World,

    So lets say I have a rhomb shape on the background and then a bunch of balls on top of it outlining and filling it.

    How would I go about making those balls constrict/shink to the center of the rhomb, and then expand back to their original position from the center of the rhomb? Would this effect be applied to the rhomb shape and have the balls pinned to it, would it be applied to the balls, or how do I do it?

    Thank you.

    P.S. Keep in mind that(for other reasons) those balls will olso have the physics behavior on them. I don't know if this matters or not, but I figured I'd trow it in there just in case there is a chance that what you are about to suggest might conflict with the physics behavior, cause that one is there to stay.

    P.S.S Olso I would like that constrict/expand effect to happen ad infinitum, not just once, regardless of what happens to some of the balls(like if some get destroyed for example). I say this just in case there isn't a easy way to do it with a behavior or effect or something(like the rotate behavior for example), and in case I have to manually do it with events, those events have to loop continuously.

  • i am not entirely sure but i think pin would not work here, as the rhomb does not move...

    my approach would be to set the oject scale of the balls and move them closer to the center...

    something like

    each x seconds  balls set scale to balls.scale -0.05
                    balls move 1px at angle angle(balls.x,balls.y,rhomb.x,rhomb.y) [/code:m11rrn8f]
    but thats when the balls are not in motion... you can also try to use a force on the balls directing to the center of the rhomb and as closer they get the lower is the scale 
    [code:m11rrn8f]balls set scale to distance(balls.x,balls.y,rhomb.x,rhomb.y)/100[/code:m11rrn8f]
    hope that helps
    kind regards 
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well, I tried your suggestions j0schi but sadly they didn't work.

    The first one has 2 problems:

    1. There is no .scale as far as I can see that I can add in the expression "set scale balls.scale"

    2. While the movement part does seem to do what I want, it doesn't adress the part that once they reach the center of the rhomb I want them to expand/move back to their original position.

    The second suggestion doesn't work at all for what I want. Because if I set it like that then the balls that are farther from the center start way bigger then the rest. I need all of them to start/end at the size that I originally set them to.

    Any other ideas guys?

    P.S. Sorry if I'm not explaining it too well guys, it's the damn heat!! After every 2 letters typed I have to stop to wipe the sweat from my brow.... I can't work like this!!!:( So let me know which parts are unclear and I'll try to do a better job at explaining them.

  • regarding the 2nd suggestiion you can also work with distance traveled (set the starting xy for each ball and calculate the distance to the current position) or with the proportion of that to the distance to the rhomb its just math XD can you provide a capx?

  • Yeah.... If there's one thing I hate in this world it's math mate!! Funny how I got into game development considering.<img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink"> Guess that's the magic of programs like C2, hide that ugly math as much as possible!!!:P

    Sure, here's a basic capx. Things to keep in mind:

    1. You can look but you can't touch when it comes to the physics behavior. That's how it is in my game and that's how it has to stay.

    2. The rhomb can be resized and made bigger in case you need more space for whatever you come up with, but I'd really rather we not mess with the initial size of the balls.

    https://www.dropbox.com/s/597trf9v7b1a5 ... .capx?dl=0

  • i dont think this is perfectly possible or even usefull as all objects check for collission and collide with each other... i think i cant be of much help here, as i dont get the use of it <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    some approach:

    https://drive.kyberon.net/index.php/s/1FPhBAiihCmSqnJ pw: test

    sorry i couldnt be of more help here, but i would suggest to approach this from another direction



  • Well, thank you for trying mate.

    Anyone else?

  • Instance variables of each ball:

    sizex <- width

    sizey <- height

    startx <- sprite.x at start

    starty <- sprite.y at start

    You probably know the center of your rhomb in x and y too. So the movement and size can be tweened quite simply back and forth. There are behaviors that do it, like LiteTween (behavior-litetween_t70700) or you can do it by yourself with the event system and some simple expressions (http://gizma.com/easing/ for reference).

    About balls touching each other:

    Be aware that they will necessarily touch each other, if they all reach the center of the rhomb, so you might want to stop a tiny bit earlier.

    You can try to tweak the size reduction yourself (let it reach "0" a bit earlier than finishing the movement), or do the math and check how large (relative to starting size) each ball can be along the timeline.

    I'm not sure how moving the balls via events by setting the position interacts with the physics behavior. Maybe there are problems or even easier solutions I am not aware off - I have not used the physics behavior so far.

  • This should do it if you give the balls two instance variables dx and dy:

    start of layout:
    --- ball: set dx to self.x-rhomb.x
    --- ball: set dy to self.y-rhomb.y
    global number t=0
    every tick:
    --- set t to cosp(1, 0.5, time)
    --- ball: set x to rhomb.x+lerp(0,self.dx,t)
    --- ball: set y to rhomb.y+lerp(0,self.dy,t)
    --- ball: set size to (lerp(0,32,t), lerp(0,32,t))[/code:3p4f7h1b]
    The cosp() equation is the only one you'd need to tweak.
    With cosp(1, 0.5, time) it will take one second to go from full size (32,32) to half size (16,16), and another second to go back to full size.
    1 is full size and 0.5 is half.  You can change those.
    You can make it go twice as fast if you multiply time by 2.  To make it half as fast multiply by 0.5.
  • Hahaha, that's perfect R0J0hound !! Just what I needed. Where you guys come up with those stuff(like cosp for example) I'll never understand.

    But it works, so thank you very very much.

    And thank you too mindfaQ , I downloaded the behavior but haven't tried it yet. For whatever reason I decided to go from end to start(I'm weird like that) so I ended up trying R0J0hounds suggestion first, and since it works I'm gonna stick with it for now.

    But I am gonna test that behavior too, and even if I don't end up using it now, knowing of it's existence is sure to prove usefull one day.

    Thank you all again.^^

  • 1. There is no .scale as far as I can see that I can add in the expression "set scale balls.scale"


    set object scale to (balls.width/balls.imagewidth)

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