Making a sprite bounce off a solid using 8direction movemen.

0 favourites
  • 10 posts
From the Asset Store
Bouncing ball
$9.99 USD
Template for a bouncing ball game, fully documented in comments and video
  • The player object/sprite moves with 8 directional movement, I want the player to bounce off solid objects, similar to how the bullet movement can, but I can't work it out.

    Reversing the 8player movement works but isn't the right solution, the player should bounce off at an angle and keep its direction, not go back on itself.

    Download:

    dl.dropboxusercontent.com/u/4044336/ss.capx

    Any help appreciated, thanks.

  • So how long would you like the player to not have control over his sprite?

  • Ideally they just bounce off and you can still control them the whole time.

  • I was asking, because if the player is pushing up-left, there couldn't be a bounce,..

    Well, the bounce would be there, but would immediately be overwritten by the move up-left..

  • I've done this in Game Maker no problem, but that wasn't using 8 direction movement, was custom movement. So maybe I'll have to create something like that again.

    After your post I understand 8dir movement a bit better, I need to to be able to carry momentum.

    Thanks.

  • Well you could set vectorX and vectorY and have it subtract from that on key down or something..

    But you might be better of using custom movement anyway..

  • Yeah custom movement seems like the better option for this. I've only just started with C2 but have used other software.

    Thanks for your helps LittleStain.

  • Oos

    You could also use the bullet behavior to handle the bounce:

    https://dl.dropboxusercontent.com/u/542 ... _8dir.capx

    For more precise bouncing you'll need to find the angle of the object hit.

    Maybe something like this:

    viewtopic.php?f=147&t=152906&p=964827&hilit=normal#p964827

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The file you linked was great until you try it from the top, you just get pushed through the wall instead.

    Gonna look at this other topic now, thanks.

    Just as a side note, how do I +rep people on here?

    edit: the other example is good too, but breaks when I add 8dir movement to the player. Also seems overly complicated for what I wanna do, I'll only be working with blocks, no slopes or circles.

    I'll keep messing around see if anything works, ty for your time.

  • For the other example you'd have to tweak it to use the 8dir movement instead of what it uses now.

    With just horizontal and vertical walls you could use the overlaps at offset condition to see if there's a wall next to it and just invert the X or y vector depending on which side a wall is. You could do it like the following. The first step would be to get the Sprite out of the wall, that is where custom movement is useful. On another note you could also compare the X and y velocity in addition to the wall detection, since you only need to bounce against walls you're moving toward.

    Sprite overlaps wall

    Sprite: customMovement: push out of solid

    Sprite: overlaps wall at offset (-1,0)

    Or

    Sprite: overlaps wall at offset (1,0)

    Sprite: set xvelocity to -self.xvelocity

    Sprite: overlaps wall at offset (0,-1)

    Or

    Sprite: overlaps wall at offset (0,1)

    Sprite: set yvelocity to -self.yvelocity

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