Bounce math

hgkjfhfdsj

Active Member
Reaction score
55
im having trouble with the maths behind bouncing projectiles.

my code so far:
JASS:
function Data_bounce takes integer this returns nothing
    local real a = RAbsBJ(udg_angle[this]*bj_RADTODEG)
    if 2*a< 90 or 2*(180-a) < 90 then
        set a = udg_angle[this]
        if a> 0 then
            set a = bj_PI - a
        else
            set a = -a - bj_PI
        endif
        set udg_angle[this] = a
    else
        set udg_angle[this] = -udg_angle[this]
    endif
endfunction


what my code is supposed to do is flip the angle (produced from the angle of contact) to the direction that is closest to it (a < 45 from direction). the problem with this is that it assumes the object the bounce occurs is a square. eg

========
a ?
?

"|" = projectile
"=" = wall

if a < 45 then the projectile will bounce north-westly which goes right through the wall (it should be bouncing south-eastly to avoid going through the wall).
random pic if it helps
Picture5.png
[/IMG]

anyone know a better math than this. dumb it down for me if possible (terrible in maths :rolleyes:)

if u need the whole code or happen to need a demo map please tell me
my original aim for this code is a jass version of pudge war's meat hook. (not that this info will help)

thanks
 

Sevion

The DIY Ninja
Reaction score
413
You need to know the angle of the wall first. Once you know that, you can just do 2 * angOfWall - angOfHook after clamping the values between 0 and 360.

You can clamp it between the range by using mod.

JASS:
function GetReflectionAngle takes real angOfHook, real angOfWall returns real
    set angOfHook = angOfHook - I2R( R2I( angOfHook / 360 ) ) * 360
    set angOfWall = angOfWall - I2R( R2I( angOfHook / 360 ) ) * 360

    return 2 * angOfWall - angOfHook
endfunction


Source: http://www.ultrashock.com/forum/viewthread/5194/

A quick Google Search always helps. Remember, GIYF.
 

hgkjfhfdsj

Active Member
Reaction score
55
var r = 2*wallAngle - this.getVelAngle();
r *= Math.PI/180; // convert angle to radians
// ...
var v = this.getVelMagnitude();
//...

- is it me, or is ur equation slightly different to the source? xD how did u get that equation?
- how do u get the angle of wall?? direction from hook to wall?? or facing of wall?

i partially used Kenny's version as reference for the maths, but the maths was too much for me lol.
 

Sevion

The DIY Ninja
Reaction score
413
My is different in only the fact that he is changing the velocity and magnitude of the vector (the hook).

The angle of the wall is two points and the angle between them. I'm not sure how to get it with just one point.

You could use a circular reflection boundary.

CircularReflectionBoundary.png


Where A is congruent to B.

From this you should be able to make some right angles and congruent triangles to figure something out.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top