Hi, first of all I want to say sorry if this problem has already been solved for someone else, I didn’t find it with search function. Then, I want to say I’m a beginner with flash and object development ( yep, parents don’t teach that to their little girl T_T )
Explication about the animation* (You can not to read that if you want to see the problem first ) :
Well, I’m making a game with a moving avatar (it moves by itself ), his direction is given by a vector which only change when colliding with another object (which I called Mirrors ). So my avatar has a moveX and moveY properties ( sort of vector so ).
And by clicking and holding the click to somewhere else, then releasing it, you can trace line (Mirrors) which have properties like start and end coordinates, a normalized vector for them, and a normalized normal vector.
When the avatar is colliding with a mirror, its move vector change, to be redirected like with a mirror reflection.*
Here are problems :
I have two problems, first and I solved it even if I think there is a better solution :
The collision is only check before the avatar move, so if my avatar move 3 pixels by 3 pixels, and if my mirror is like x = 5-10, my avatar x = 1, it will move one time : avatar.x = 4, no collision. second time : avatar.x = 7 : collision, but my avatar is partially “in” the mirror, so weird… To solved it, my avatar only move 1 pixel by 1 pixel… But it’s so weird to act like that, so, is there another solution ?
Second problem, when my avatar come in contact with the “bottom” or “top” of my line (imagine a vertical line), it does some strange things like go through the line and shaking… I don’t know how to manage that, it actually occurs sometimes even if it does hit at the line itself. I don’t know why.
Here are the files :
You don’t need to use my .fla, you can make your own and just put the Reflectio.as as a document class.
I commented my code, and I would be happy if you give me advice to make a better code, as I said, I’m a newbie.
I use a collision detection class that I found on the internet apparently written by Troy Gilbert.
Thanks for reading, and hope you could help me, and maybe my calculation for reflection could help someone else.
See ya
Litchi ~