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

Get help using Construct 2

Post » Thu Nov 17, 2016 2:16 pm

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)

Image

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.
Last edited by tunepunk on Mon Nov 21, 2016 10:41 pm, edited 1 time in total.
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 991
Reputation: 12,654

Post » Thu Nov 17, 2016 2:24 pm

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.
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 991
Reputation: 12,654

Post » Thu Nov 17, 2016 3:02 pm

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.
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 991
Reputation: 12,654

Post » Thu Nov 17, 2016 3:57 pm

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;

Image

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

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.
Image
B
108
S
24
G
18
Posts: 1,372
Reputation: 22,817

Post » Mon Nov 21, 2016 9:20 am

@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.

Image

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?
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 991
Reputation: 12,654

Post » Mon Nov 21, 2016 10:42 am

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.
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 991
Reputation: 12,654

Post » Mon Nov 21, 2016 2:36 pm

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?
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 991
Reputation: 12,654

Post » Mon Nov 21, 2016 7:28 pm

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:

Code: Select all
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


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.
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999

Post » Mon Nov 21, 2016 8:15 pm

@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.
Follow my progress on Twitter
or in this thread Archer Devlog
B
40
S
17
G
17
Posts: 991
Reputation: 12,654

Post » Mon Nov 21, 2016 8:32 pm

Just want to give the idea:
alextro wrote:update #2 shoot da babble02.capx
Image
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.

Image
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.
ImageImage
B
108
S
49
G
23
Posts: 783
Reputation: 22,611

Next

Return to How do I....?

Who is online

Users browsing this forum: Kin and 44 guests