I want bounce a ball on differents rectangular boxs without behaviors because i need to keep the x/y variables and then pass them through a relocation pass before the ball is drawn to the screen...

So i move the ball with :

System every tick - ball set X to Self.X+Self.speed_x*dt
- ball set Y to Self.Y+Self.speed_y*dt
[/code:mnqr0lnu]
I have the angle of motion of the ball with a function that i create.
For the collision with a box i use :
[code:mnqr0lnu]
Ball is overlapping box
[/code:mnqr0lnu]
Now i don t know how to use the angle of motion to bounce off the ball .
I try to reverse x y coordinate with
[code:mnqr0lnu]
X=cos(angleofmotion)
Y=sin(angleofmotion)
[/code:mnqr0lnu]
But the result is not very correct , the ball bounce off but not very realistic..
Thx for help

I don't have time to work on anything right now but quick thoughts are:

1) Use the speed x and speed y variables to change your angle of motion. It's moving using those variables so altering it's X and Y coordinates is going to look strange since every tick you're still using those variables to push the ball in a particular direction. You can create another set of variables (e.g. X and Y constants - perhaps 0 and 200, respectively) to compare to whatever you change your variables to. If your speed variables are greater or smaller you bring each variable back to your constants every X seconds or tick with a small sum.

2) Create imagepoints around your ball to determine where it's overlapping to determine the angle of motion you want and create a system that alters your X and Y speed variables accordingly.

Isn't a bounce basically a negative value of x speed and y speed ( - drag/friction if necessary ), so if something is moving at yspeed of 10 and hits the bottom, y speed becomes 10*-1 ( or *-0.9 to simulate slowdown due to friction ) x speed stays the same. Hitting sides you multiply xpeed by -1 and y speed remains the same.

At least this is the basic way to do it, no angles are necessary.

Thx BadMario for your explanation, it's a basic rebound that I wish so if I do not need the angle and I change the x and y depending on the side of the box touched, my question is how we determine the side hit ? thank you !

I find this formule from an old game in AS3 ( flash game )

// hold our ball position
var bx:Number = _main.mcBall.x;
var by:Number = _main.mcBall.y;
var br:Number = _main.mcBall.width * 0.5;
// get our bounds (assuming that the brick has it's registration point
// in the center) - extend by the radius of the ball to cover the points
var left:Number = this.x - this.width * 0.5 - br;
var right:Number = this.x + this.width * 0.5 + br;
var top:Number = this.y - this.height * 0.5 - br;
var bottom:Number = this.y + this.height * 0.5 + br;
// check the position of the ball in relation to our brick
if( ( bx >= left && bx <= right && by >= bottom ) || // bottom
( bx >= left && bx <= right && by <= top ) ) // top
{
_main.mcBall.ballYSpeed *= -1;
}
else // hit the left or the right
{
_main.mcBall.ballXSpeed *= -1;
}
[/code:2j92k98u]

set each wall either as a variable ( leftwall = 0 for example ) or if using the actual object it would be leftwall = leftwallobject.X+leftwallobject.Width/2

if ball.X < than leftwall ball.X= leftwall+ball.Width/2 and also multiply x speed by -1 to reverse it.

Do same for each side, obviously for the right side it will be if ball.X > than rightside