How do I calculate angle of platformer bouncing on circle

0 favourites
  • 9 posts
From the Asset Store
10 Retro songs ideal for platformers or farming games
  • I have a character with a platformer behavior on it. and i'd like the to bounce when they fall onto a semi circle bouncy ball sticking out of the ground. I'll apply a X and Y vector to it when it collides, but i'm not sure how to calculate the angle so that when they hit the top part of the circle they bounce more upwards, vs when they hit more of the side of the circle they would bounce at an angle backwards and more like real life.

    I guess i need to figure out the "normal" angle at impact. but im not sure how to do that.

    what's the math?

    Thanks

  • As it is a semi circle cant you just, on collision, use the angle from the centre (origin / image point) of the ball to an image point on your character sprite (maybe a bit nearer the bottom ) ?

    no fancy maths needed.

    sin cos for the vectors if you need.

  • NetOne - i need to apply the vector X and Y to give the bounce illusion backwards.

    I tried

    cos(angle(player.x, player.y, bouncer.x, bouncer.y)) and sin(angle(player.x, player.y, bouncer.x, bouncer.y))

    but it didnt really do anything, even multiplying those numbers to make it a larger impulse.

  • yea so you need to multiply these vectors by the (hypotenuse) which id say a good start would be speed of your dude when he hits the ball (assuming a 100% transfer) or some factor of that speed (for more effect) then should be ok

  • justifun

    you dont really need the (sqrt(Self.dx^2+Self.dy^2)) bit in this case you can just use the dy instead or 3, its there to just make it complete if your char was moving at an angle

  • same thing with absolutely no math thanks to construct 2

    (note that this bounces at the angle of the player to the ball "normal to surface angle", which is probably good for games but not realistic, if you were going for more realism you might need add a bit or all of original movement vector angle to the normal angle and add some dampening, but as this is a big bouncy ball I think you can get away with normal to the surface ..)

  • Thanks for the examples

    How do i convert the movement to a platformers Vector X and Y impulse amount?

  • Ive never used platform but had a quick look at its expressions and

    dx and dy in the first example = exactly what would be x and y movement vectors

    And (sqrt(Self.dx^2+Self.dy^2)) = exactly what would be player speed

    So you can just substitute them over. i.e on collision with ball then player x vector = player speed * cos angle ball to player etc

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ive never used platform but had a quick look at its expressions and

    dx and dy in the first example = exactly what would be x and y movement vectors

    And (sqrt(Self.dx^2+Self.dy^2)) = exactly what would be player speed

    So you can just substitute them over. i.e on collision with ball then player x vector = player speed * cos angle ball to player etc

    I just gotta say, this worked really well. I'm doing sort of a drag and aim style of game play, but as it's for a vertical platformer, I was trying to see if there was a simple implementation using vectors and the platform behavior. works great so far!

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