[SOLVED] How do I calculate bounce angle in isometric view.

0 favourites
From the Asset Store
Bounce the ball and try to keep it bouncing and prevent it from falling down for as long as you can.
  • I wanted to have projectiles bounce of solids in isometric view, but everything seems to bounce off in a very weird way. Like shown below. (Green is the observed result which makes sense in a top view, if the obstacle had that shape)

    Is there any way to adjust the bounce of a bullet to behave more natural in isometric view, and is there any formula for that.

    Bullet behaviour has the "bounce of solids setting" which only seem to work in pure 2d scenarios.

    Is there any way to solve this? Been scratching my head a while with this one.

    There doesn't seem to be any way to get the angle of the side of the collision box hit either.

    Any help appreciated.

  • It seems that the only way to solve this would be to use the movement angle of the bullet before the bounce, and as soon as the bounce happens (when the bullet has a new angle of motion) adjust that angle the next tick, based on some formula, but how to get there I don't know.

    EDIT: Keep in mind, the bullet can hit from any angle, and the obsatcle can be any angle. I even have some round-ish solids.

  • Think I found the answer after a bit of intensive googling.

    isometricAngle = arctan( tan(oldangle) / 2

    Will try it out when I get back home. Replacing the angle of motion after bounce with the result i get after using this formula.

  • If you're looking for a math who will ignore the angle of the wall, just make a math like this:

    Angle of entrance: 30 degrees;

    Angle of exit: 180 degrees - angle of entrance;

    But if you're looking into why the issue is happening, it's because the collision polygon is stretched when in isometric view.

    While the correct is bounce and exit the wall considering the angle of the wall in the math, if you want ignore it and make the bounce happen like watching it in topview, just add the difference between the angles.

    Using an isometric view angle of 45 degrees you'll obtain a bounce angle of 71 degrees between the entrance and the exit, while you want obtain 90 degrees, so, just add or subtract the difference to the exit angle and it should be sufficient for any entrance angle.

  • TELLES0808 Thanks for the example. Adding the difference makes sense but how do i calculate the difference? My main problem is that my isometric objects can have any shape or angle. Everything is not diamond shaped. The formula i found didn't work at all in my case. I was getting weird angles when hitting any other angle that was not "diamond shaped".

    This is what I'm after.

    I need some kind of formula that adjusts the exit angle for any object shape. or any normal vector angle hit.

    EDIT: I can't apply "atan(tan(oldAngle)/2)" directly to the exit angle. It creates weird results. I suppose that formula should be used to the normal vector hit. But since i can't adjust that, I need to adjust that exit angle AS IF it hit an angle adjusted by that formula i suppose?

    EDIT2: Is there any way i can get the normal vector by using entry angle and exit angle? adjust that normal vector with the formula, then calculate a new exit angle based on ently angle and the new adjusted normal vector?

  • Hmmmm..... Just speculating here........

    the normal vector must be entryAngle+exitAngle/2

    Entry angle (225)+ Exit angle (315) /2 = 270 makes sense. That's the normal vector.

    Exit angle = (NormalVector (270)-Entry angle (225) = 45 + Normal Vector ( 315) ... seems correct.

    Soooo .... i need to adjust that Normal vector to get a correct exit angle? atan(tan(oldAngle)/2)

    hmmmmm so basically i need to adjust any vector angle as if it was not in isometric.

  • I seem to be getting closer but i get some weird results again when i try to get the average angle between two angles... Does anyone know how to properly calculate the average angle between 2 angles that takes on to account wrap around?

    what's the angle between 350 and 20?

    I know it could either be 185 or 5, but i always need the closest one.

    What's the correct formula to use to always get the closest angle between to two?

  • You could use anglelerp(350, 20, 0.5) to take into account wraparound.

    If you're using 2:1 (width to height) isometric then here's a way to get it to bounce correctly:

    1. first if you use the bounce action with events you can get the the before and after angles which then can be used to calculate the surface angle. A simple formula to calculate the bounce is "angle_out = 2*surface_angle - angle_in", which can be manipulated to "surface_angle = (angle_in + angle_out)/2".

    2. That angle is the visual angle. To get the iso angle you take the angle and convert it to x and y components with trig. x=cos(angle), y=sin(angle). If we double the y then use the angle() expression on that it should give us the corrected surface angle. Basically "new_angle = angle(0, 0, cos(old_angle), 2*sin(new_angle))".

    As an example looking at the image in the op, the bottom left edges of the diamonds are at 45 and 26.2 degrees. Then using the formula above we can convert 26.2 to 45.

    3. Once we have the corrected surface angle we can calculate the bounce angle again with "angle_out = 2*surface_angle - angle_in". Completed pseudo example below:

    number ang_in=0
    number ang_out=0
    number ang_surface=0
    on ball collides with wall
    --- set ang_in to ball.angle
    --- ball: bounce off wall
    --- set ang_out to ball.angle
    --- set ang_surface to (ang_in+ang_out)/2
    ---set ang_surface to angle(0,0,cos(ang_surface), sin(ang_surface)*2)
    --- ball: set angle to 2*ang_surface-ang_in[/code:2hbesvcv]
    One caveat is the result isn't quite perfect because the bullet behavior seems to calculate an approximate surface angle.  In my test it calculates the bottom left edge as 27.5 degrees instead of 26.5.  As a side note it should be 26.5 because atan(y/x) or antan(1/2) is approximately 26.5.  Anyways to get more precise surface angles we need to find the angle ourselves.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound Thanks for the detailed explanation. I will try that out, and see how it works.

    I just tried a different approach where the jcw_trace plugin can give me both the normal angle and reflection angle directly without having to fire a bullet and rely on the angle it bounces off. The only problem with the values i get from this plugin is that they are in normal 2D mode.

    using the atan(tan(oldAngle)/2) formula on the normal vector i get there behaves strange as i have to flip it.

    if the normal angle is between 90 and 270 i have to add +180 at the end of the formula, otherwize that formula behaves strangely.

    So with this raycast plugin giving me both normal and reflection(exit) angle, is there a better formula to derectly adjust the exit angle for isometric based on values i can get from this plugin?

    seems better than using a bullet, in this case. Thanks a lot for your help.

  • Just want to give the idea:

    update #2 shoot da babble02.capx

    With this math expression no matter which side wall facing, bouncing direction always at correct angle.So Placing and rotating the wall freely make more sense now.

    The same method applied to shooting line "laser". only for laser we put another instance as if it bouncing off previous one.

    It bounces correctly from 2 side of rectangle shape, so you just need to create multiple normal vector for each object.

  • alextro Yeah i got that far, but my main problem was calculating the normal vector between two angles (in and out). It's too bad you can't access the collision box angles, directly with events. That would help a lot.

  • R0J0hound

    Everything worked perfectly except a small thing.

    angle(0,0,cos(Trace.NormalAngle), sin(Trace.NormalAngle)*2) was supposed to have /2 instead and all worked like a charm.

    Thanks a bunch!

  • That good it worked. The surface angle in my formula is 90 degrees from the normal angle so that explains why you needed that tweak.

  • R0J0hound

    There seem to be something wrong. Any idea what it can be? very wide angles tend to be wrong.

  • Never mind r0j0 i added you formula directly to the normal instead of the surface angle which messed things up.

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