Is there a way to control distance between multiple sprites?

0 favourites
  • 7 posts
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • Think of a juggling game with multiple balls in play. ALL the balls have to be kept in play and the player has to move to each falling ball in order to throw it. So I'm trying to figure out a way to control when each ball returns to the ground, giving the player a chance to hit each one. Otherwise, eventually it ends up where two balls return to the ground at the same time and it becomes impossible to hit both.

    So, what I am thinking is:

    Game Starts = One ball.

    Time it takes for thrown ball to return = 4 seconds

    Score is 4 = New ball is spawned (two balls)

    Each ball is 2 seconds apart from each other when travelling the air and in returning to ground

    Score is 8 = New ball is spawned (three balls)

    Each ball is 1.35 seconds apart from each other when travelling the air and in returning to ground

    Score is 16 = New ball is spawned (four balls)

    Each ball is 1 second apart from each other when travelling the air and in returning to ground

    Something like that. And that distance is always kept in play, no matter what. That way it does not become unfair and the player has a chance to reach each falling ball (if they're good enough). Am I on the right start point in thinking that maybe distance travelled could be used for this?

  • Just to talk on this more. I already have it setup where each ball follows its own arc depending on where it was hit by the players hand. So what I need to do is control the speed of each ball when a new ball comes into play so the new ball can fit in to the cycle (almost like traffic). Except, I don't think merely altering the acceleration and speed on each ball will be enough as I suspect that will still eventually lead to an unfair situation. Rather, acceleration and speed of any ball actively changes when being compared to the other balls, to create an order. I'm not too sure. I know what I want it's just I'm not sure what would be the best way to go about it.

  • Ok, I've resorted to using objects as a trigger combined with wait. So, when score is 2 and the first ball makes contact with a ceiling object, the second ball is created 2 seconds later. Using this method, with three balls in play, each one is within reach of the player and there doesn't seem to be any unfair situations.

    However, this isn't exact enough because when any ball is hit by the player, say at the side of the hand rather than on top, that thrown ball then does not get thrown as high as when it hits on top of the player hand. So eventually that will create a situation where each ball is no longer a second apart when returning to the ground.

    Right now, thrown balls is done via bullet behavior and I have it where if the ball hits the right hand, its angle arcs to the left. And vice versa. This is fine. What I have for movement is just basic bullet speed and this is what is preventing every ball from reaching the same height every time (speed of 700 when bouncing from the top of player hand will go higher than speed of 700 when bouncing from the side of the player hand). So, is there another way to make sure each ball hits an exact ceiling before gravity brings it back down again? With this, I should be able to maintain each ball always being a second apart.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You might consider moving the balls yourself, either with a CustomMovement behavior, or just by giving the balls XSpeed and YSpeed variables and Every Tick setting Ball.X to Ball.X + Ball.XSpeed*dt and Ball.Y to Ball.Y + Ball.YSpeed*dt.

    This way you'll have control over each axis separately (I don't know if the behavior you are using already allows that). You want the YSpeed to always be the same no matter what kind of hit. For angled hits, add a little speed to the XSpeed to bounce it off to the side. The effect this will have is that angled hits will move quicker through the air (since their overall speed will be higher), but their YSpeed will be the same, causing them to come back down at the same time.

    Now, this method might serve you for short play times, but due to the various inaccuracies that occur due to the ball hitting the player at different offsets (sometimes at lower Y coordinates, sometimes at higher Y coordinates, and at slightly different times, with a fluctuating frame rate), over long plays you might find that it becomes unfair again, even though the initial offsets were correct. For this reason, I would suggest re-enforcing the offset right after a player hits it. You might try saving the time offset in the ball, and then when you hit a ball, use Ball.Offset and the current time to determine when to release the ball upwards so that it falls back into its correct pattern.

  • Er, you've lost me. Under what action should I use for those variables?

  • Right, so, using what you suggested I now have the ball falling to the ground from up above when created, it bounces off the players hand and I've got the angle (Set vx to BallSprite1.vx-120).... I just need to work on some form of gravity. Now, do I do that with the vx and vy or should I just use bullet gravity for bringing it back to earth?

  • Ok, phew, done it. The ball hits the same height all the time. What I need to figure out now is how to introduce more balls at the exact right time, so each ball can potentially be hit by the player every second. No longer, no sooner. Should I do this by simply using wait triggers or should this be a little more complex and require timers?

    First I have to time how long it takes the ball to drop from the top of the screen to the bottom. I have set up a time variable to do this but my issue is it only counts in seconds (right now, with the set gravity it takes two secs to drop from the top to the bottom and four seconds to bounce from players hand, reach the top of the screen, and fall bck down). I need more detail than that so how do I use the time variable to count milliseconds as well?

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