How do I make a parabola effect for coins?

0 favourites
  • 2 posts
From the Asset Store
112 High-Quality Coins and Chest SFX specially crafted for video games
  • Hi everyone. I have a math and logic problem for you. And it might be something a little too complicated. In short, I need the coins that respawn between platforms to make a parabola.

    To tell the truth, I have many difficulties and this is just one among others:

    1. How do I make the coins respawn "in block"? That is, all together?

    2. What is the mathematical expression that allows me to replicate a parable?

    3. How can I make the number of coins increase or decrease according to the distance among platforms considering that it is always random?

    Here down I've a sketch for you.

    It's not the best but I think it manages to deliver the concept.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can rough it out by doing a loop. x0,y0 would be the first point, and x1,y1 would be the second.

    repeat 10 times
    -- create coin at (lerp(x0, x1, loopindex/9), qarp(y0, y0-200, y1, loopindex/9)

    you can make it place more or less depending on the width of the gap.

    repeat (x1-x0)/32 times
    -- create coin at (lerp(x0, x1, loopindex/int((x1-x0)/32-1)), qarp(y0, y0-200, y1, loopindex/int((x1-x0)/32-1))

    The 32 is to space the coins out horizontally every 32 pixels.

    The 200 to strength of the parabola.

    Here's also a way to automate calculating the two positions between each two plats from left to right.

    global number prev=0
    global number x0=0
    global number y0=0
    global number x1=0
    global number y1=0
    start of layout
    for each plat ordered by plat.x ascending
    -- loopindex > 0
    -- -- set x0 to plat(prev).x+plat(prev).width
    -- -- set y0 to plat(prev).y-plat(prev).height
    -- -- set x1 to plat.x
    -- -- set y1 to plat.y-plat.height
    -- -- repeat ....
    -- -- -- do stuff
    -- set prev to plat.iid

    Anyways the coins will basically be equally spaced horizontally, but vertically they will vary in spacing. We can make them equally spaced along the path, but it's more complex. It amounts to making a path of straight lines, and measuring the length between each point, and adding them all together to get the total length. Then it's possible to move along the path by a certain distance at a time. I probably won't do a description justice. The example in the end does it.

    Another thing you can do is relate the arcing of the parabola to the platform behavior's jumpStrength and gravity. You asked what the formula for a parabola is, and for the platform behavior it's:

    x = x0 +vx*t

    y = y0 +vy*t + 0.5*gravity*t*t

    You can use that to solve for t to by plugging in -jumpStrenth into vy. That would give you the total time of the jump. Then you can do this to get a path close to the platform movement jump.

    set totalTime to (JumpStrength+sqrt(JumpStrength^2+2*Gravity*(y1-y0)))/Gravity
    repeat 10 times
    -- set t to loopindex/9
    -- create coin at (lerp(x0, x1, t), y0-jumpStrength*t*totalTime + 0.5*gravity*(t*totalTime)^2)

    At any rate here's the example of me playing around with the idea. Maybe some of it is useful.

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