|
-
May 25th, 2008, 07:45 PM
#1
Thread Starter
New Member
Ball Bouncing Trig
ello, i am trying to have a ball bounce around the screen but i want to be able to draw lines and have the ball bounce off of the line accordingly. Unfortunately i am only in Pre-calc and have not learned enough to be sufficient. I've been trying to decipher the physics in this ACTIONSCRIPT CODE
Code:
ACTIONSCRIPT:
1.
_root.attachMovie("arrow", "arrow", 10001);
2.
_root.attachMovie("bounce", "bounce", 1000);
3.
arrow._x = 150;
4.
arrow._y = 150;
5.
bounce._x = 150;
6.
bounce._y = 150;
7.
arrow.onEnterFrame = function() {
8.
mousex = _xmouse-150;
9.
mousey = (_ymouse-150)*-1;
10.
angle = Math.atan(mousey/mousex)/(Math.PI/180);
11.
if (mousex<0) {
12.
angle += 180;
13.
}
14.
if (mousex>=0 && mousey<0) {
15.
angle += 360;
16.
}
17.
bounce_angle = 180-angle;
18.
if (bounce_angle<0) {
19.
bounce_angle += 360;
20.
}
21.
_root.angletext.text = "Angle: "+angle;
22.
_root.bouncetext.text = "Angle: "+bounce_angle;
23.
this._rotation = angle*-1;
24.
bounce._rotation = -bounce_angle;
25.
};
but i can't seem to get it to work.
This is the code that i have so far.
Code:
Dim mousex, mousey As Double
Dim AendX, AendY As Double
Dim linelength As Single
Dim angle As Single
Const Pi As Double = 3.1415926
Dim AngleRadians As Double
Dim AngleDegrees As Double
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
mousex = X
mousey = Y
End Sub
Private Sub Timer1_Timer()
arrow.X2 = mousex
arrow.Y2 = mousey
AendX = mousex - linelength
AendY = mousey - linelength
linelength = Sqr((arrow.X2 - arrow.X2) ^ 2 + (arrow.Y2 - arrow.Y1) ^ 2)
Label1.Caption = linelength
AngleDegrees = Atn(mousey / mousex) / (Pi / 180)
Label2.Caption = AngleDegrees
End Sub
Right now i am trying just to get the core trig out of the way using this

The x2,y2 coords follow the mouse and i'm trying to find the angle which the line makes with the flat line(landscape)
Please help me and please try to explain the trig easily
-
May 27th, 2008, 06:32 AM
#2
Re: Ball Bouncing Trig
Moved To Games and Graphics Programming
-
May 27th, 2008, 07:19 PM
#3
Hyperactive Member
"Why do all my attempts at science end with me getting punched by batman?" xkcd.
| Pong| |
Sorry for not posting more often.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|