Well I haven't been able to use SC2 at all, so I don't know how to specifically do this in the SC2 editor.
If you have a 45 degree angled wall, you switch the x and y velocities.
For things other than it gets a bit more complicated. Here is one method:
Imagine your wall being intersected by a horizontal line. The smallest angle formed by this intersection is represented by A. When a ball hits an angled surface, you modify the angles of the velocities. You modify the x velocity by setting it equal to pie/2 + A. You set the angle of the y vector to pie/2 - A. Your new vectors will represent the velocities of the object after it hits the wall, however, they aren't in a form that can easily be interpreted as x and y velocities, they are now in perpendicular and parallel velocities (to the wall). So what you do is convert the parallel and perpendicular into new x and y velocity vectors by plugging a few variables into an equation.
For simplicity's sake, the parallel = f(V
xcos(A) + V
ysin(A)). The perpendicular = -e(V
ycos(A) - V
xsin(A)).
So now you need to modify these two velocities back into x and y representations.
Here are the equations for the final velocities of x and y.
New V
x = V
x(fcos
2A - esin
2A) + V
ysinAcosA(f + e)
New V
y = V
xsinAcosA(e + f) - V
y(ecos
2A - fsin
2A)
You can plug A and the x and y velocities into these two equations to solve for the new velocity vectors after a collision with a wall, in which the A angle represents the smallest angle formed by an intersection between the wall and an imaginary horizontal line.
Here is my source:
http://www.newgrounds.com/portal/view/448915The only thing I didn't understand was what f and e were. I'm assuming e is Euler's number, and I'm not sure what f is. You should probably get someone else in here like Lethal.
Also, there is a really simplified notation out there that uses the dot product along with the perpendicular and normal velocity, and the velocity of the object. This is what I myself would use, but I don't want to explain how to use the dot-product without having matrix representation.
This is basically the exact same for three dimensions, just with an extra velocity vector z. If you want to have collision between two balls, then you need to calculate the slope of the line formed between the center of each circle. This is easy, rise over run. To get the rise over run you use the Pythagorean theorem (also known as the distance formula) on both of the center points from each circle. Once you get the slope, reverse the numerator and denominator to get the perpendicular, then do the entire above process using this perpendicular slope as your "wall" to collide with.
Post has been edited 1 time(s), last time on May 6 2010, 5:21 pm by CecilSunkure.
None.