How Do I Replicate This Bounce Effect?

0 favourites
  • 10 posts
From the Asset Store
A total of 214 high quality and unique magic sound effects suitable for RPG, Battle Arena and more!
  • First of all, I am new to Construct 2 and prior to asking this I have looked through various threads and experimented with numerous movement types including; Sine, Custom Movement and Bullet to achieve this effect to no avail.

    I've created a JSFiddle to show you exactly what I am trying to do here: jsfiddle.net/cCfDb/ � basically as you can see the ball is bouncing consistently in a sine type movement. How would I go about replicating this JSFiddle example I've created in Construct 2? As my example is HTML5, is there perhaps a way I can use some of this code?

    To put it simply, the ball needs to bounce off each wall, there are 4 walls (1 top, 1 bottom, 1 left and 1 right). And it just needs to hit a different part on each wall every time it hits it. So it needs to go around in a circular part, it can't go up and down (just essentially like my linked example).

    Any help would be gratefully appreciated. If I didn't provide enough information, please let me know and I can provide whatever I can to help you assist me. I hope to be proficient in Construct 2 soon, so I too, can help others like myself.

  • Add Solid behaviour to your wall spite - make four and place at each side. Give ball sprite Bullet with 'Bounce off solids' behaviour. Set a starting angle (let's say 40) - done.

  • Add Solid behaviour to your wall spite - make four and place at each side. Give ball sprite Bullet with 'Bounce off solids' behaviour. Set a starting angle (let's say 40) - done.

    I essentially tried the same thing, but the bounce doesn't consistently hit each wall. The bounce either becomes too predictable (pattern never changes) or it doesn't do the sine effect I am after where the ball should hit each wall once, just a different spot each time.

    As you can see in my posted JSFiddle, the ball consistently touches each side. With the bounce behaviour and movement set to bullet, the ball could bounce up and down, side to side, corner to corner, but not achieve the sine bounce I am after.

    I want there to be somewhat of a pattern in movement, but hit a different point each time. This will allow users of the game to use tactics because the movement will be the same touch each side of the wall once movement, but it will slightly randomise the path roughly every 5 seconds or so.

  • Bullet Gravity might be worth experimenting with - set > 0 and then tinker... Bouncing within a rectangular container like that will always yield predictable patterns unless you add a random element to it - gravity is predictable but will change the ball's dynamics so you could also change the ball's angle by a slight random amount on every wall collision.

  • To add some unpredictability, you could simply set the density, friction, elasticity or any of the other options to CHOOSE or RANDOM pick a certain number of values, and set it to every few seconds. That way, you are guaranteed to get some different results each time.

  • Digitalsa

    Why not do it just like your code?

    You have this:

    if (x + dx > WIDTH || x + dx < 0)
        dx = -dx;
      if (y + dy > HEIGHT || y + dy < 0)
        dy = -dy;
    
      x += dx;
      y += dy;

    Which is all doable with events.

    This tutorial may be of help to get you up to speed: https://www.scirra.com/tutorials/37/beginners-guide-to-construct-2

  • Digitalsa

    Why not do it just like your code?

    You have this:

    if (x + dx > WIDTH || x + dx < 0)
        dx = -dx;
      if (y + dy > HEIGHT || y + dy < 0)
        dy = -dy;
    
      x += dx;
      y += dy;

    Which is all doable with events.

    This tutorial may be of help to get you up to speed: scirra.com/tutorials/37/beginners-guide-to-construct-2

    I feel so silly, but you're right. After giving it a little more thought, the code in the JSFiddle I posted isn't all that difficult in Construct 2 using events. I'll let everyone know how I go. I'll give it a shot converting over my fiddle code to C2.

    Thank you for your help. I think the long stressful week just fried the logic part of my brain.

  • Sadly replicating the above code was a difficult experience for me. Would it be possible to get a little help with this? I would be happy to pay a small sum of money for the right solution. I want to learn, a simple bounce that touches each side without doing weird things like bouncing side to side or up and down. It seems like it shouldn't be that difficult, but it is and after countless searching it seems that this is an issue many have struggled with.

    Just let me know what you need and I'll supply it. I can talk over Skype if that helps.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Just taking R0J0s code I get :-

    https://www.dropbox.com/s/j2js9jokjs5sn ... e5d4m.capx

    If this is what you want and if you were serious about a small sum of money then please place this small sum into a children charity box.

  • Just taking R0J0s code I get :-

    https://www.dropbox.com/s/j2js9jokjs5sn ... e5d4m.capx

    If this is what you want and if you were serious about a small sum of money then please place this small sum into a children charity box.

    Thanks for the link mate. Will check that out shortly. And yes, I was serious about the cash and I completely agree with donating it to a children's charity, I will do just that. There is one fantastic community here!

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