Need help to find a math equation...

OneBadPsycho

10100111001
Reaction score
93
Hello, I have searched and searched over the Internet for an equation for a ball hitting a wall and then changes angle... (Thoose i found didnt fit my needs)
Like this:
1211110184_U1Fk3fqc.jpg


I would apprieciate if anyone can give me the equation/formula.

Thanks in advance.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Ok that was a lot easier than what I had in mid, using the pythagorean theorem to calculate the distance from the wall to the ball's previous location, then from there calculating the angle from the previous point to the wall, multiplying that by 2 and then subtract that from 180 xD.
 

OneBadPsycho

10100111001
Reaction score
93
@Larcanist
Its sliding.

@Flare
Hmm, it doesn't seem to work properly.

This is my code:
Code:
Wall
    Events
        Unit - A unit enters Bound 1 <gen> [B](This region is ontop of the map. I have 4 bounds, 1 in each side, so if the trigger could be made to include all the bounds, it would be nice)[/B]
    Conditions
        ((Entering unit) is in SpellUg) Equal to True
    Actions
        Set OLoc = (Position of (Entering unit))
        Set OAngle = (Facing of (Entering unit))
        Unit - Move (Entering unit) instantly to OLoc, facing (OAngle + (2.00 x (0.00 - OAngle))) degrees
        Custom script:   call RemoveLocation (udg_OLoc)
        Custom script:   set udg_OAngle = 0
The unit just keep moving up and down at the line like periods, until it dies: (The green line)
skop-start.jpg
 

OneBadPsycho

10100111001
Reaction score
93
270 works at bound 2, which is to the left, but its still moving like periods, could that be caused because of the summoned/slided unit still in or reenters the region?
 

OneBadPsycho

10100111001
Reaction score
93
But i think he actually moves abit further than the region before it change angle... Sec, gonna check it.

Edit: Got it to work, I just increased the region sizes! :p
Anyway, thanks +rep! :thup:
 

OneBadPsycho

10100111001
Reaction score
93
It wont work properly...

Flare, the math equation doesn't work properly (I think), could you please take a look at my map?

Thanks in advance! :)
 

Attachments

  • Chaos.w3x
    26.5 KB · Views: 106

Ninja_sheep

Heavy is credit to team!
Reaction score
64
The angle it goes to and the angle it comes from are always the same.
reflection%20on%20water.jpg
angle 1 and 2 are always the same. Doesn't matter in wich angle the ball hits the wall.

The only problem is to find the angle of the wall. If you only have walls that go south-north and east-west it shouldn't be too much of a problem.

Hope noone posted that before :p
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Lets say the unit is bouncing off the wall at the top or the bottom.

The only difference in the velocity of the unit and angle is that the y velocity is changing to up from down or vice versa.

So what you need to do is split the angle into its x and y values, and make the y value negative:


trig_sin_cos_tan.gif


Since Cos(θ) = X / Velocity
and
Sin(θ) = Y / Velocity

The X = Velocity * Cos(θ) and
The Y = Velocity * Sin(θ)

Making it bounce off of a wall that is above or below the unit would be inverting the Y, and making it bounce off of a wall that is to the left or right of the unit would be inverting the X (negative x/y)

so if you want it to bounce off a top or bottom wall:

Angle = @
X = Velocity * Cos(@)
Y = Velocity * Sin(@)
Set Y = 0 - Y

Now to get the Angle back,
Set @ = Arctan(Y/X)

The only difference for a left or right wall would be setting X = 0 - X instead of Y.

If you post your trigger/code with the sliding, I can help you implement it into your map. :)
 
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