The process I am using to scale down my velocity vector while maintaining the same angle of motion is as follows:
1. Find the magnitude of the vector
2. Normalize the vector
3. Decrease the value of the magnitude by a friction constant
4. Multiply x and y velocity components by the new magnitude
My code looks like this:
Code: Select All | Copy To Clipboard
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | .PUTTPUTT P*16**cos(θ)->V //P represents power, used to determine how fast the ball will move P*16**sin(θ)->W //V is the X-velocity; W is the Y-velocity Repeat getKey(15) Pt-On(X+V->X/256, Y+W->Y/256, Pic0) //X and Y are the position components 127*W//sin(tan-1(V,W))->M //M is the magnitude of the velocity vector M-F*W//M->W //F is the friction constant. I multiply the new magnitude by each component before dividing by the current magnitude M-F*V//M->V //because W//M would give a value of 0 If X/256>90 -V->V End If Y/256>59 -W->W End DispGraphClrDraw End |
Depending on P and θ, the code may or may not work, and I can't figure out why; the ball does seemingly random stuff, often not even going in the right direction.

Also, I don't know if this is relevant, but when I debugged the magnitude, it changed whenever the ball bounced off the left or right of the screen, which I don't think should be happening.
Can anybody help me fix this?


