Note that there are some explanatory texts on larger screens.

plurals
  1. POActionscript collisions: solving exceptions and strange cases
    primarykey
    data
    text
    <p>I have created a collision class to detect collisions using pixels. In my class I've also developed some functions for determining the collsion angle. Based on this I created some examples:</p> <p><a href="http://megaswf.com/serve/25437/" rel="nofollow noreferrer">http://megaswf.com/serve/25437/</a></p> <p><a href="http://megaswf.com/serve/25436/" rel="nofollow noreferrer">http://megaswf.com/serve/25436/</a></p> <p>(Space to change gravity, right/left to give some speed to the ball.)</p> <p>As you will probably notice, there are strange things that happen:</p> <ul> <li>When the ball speed is very low</li> <li>When the direction of the ball is almost tangent to the obstacle.</li> </ul> <p><a href="http://img514.imageshack.us/img514/4059/colisao.png" rel="nofollow noreferrer">collision http://img514.imageshack.us/img514/4059/colisao.png</a></p> <p>The above image shows how I calculate the collision angle. I call the red dots the keypoints. I search for a maximum number of keypoints (normally 4). If I find more then 2 keypoints, I choose the 2 farthest ones (as shown in one of the blue objects). Thats how I then find the normal angle to where in the surface the object collided. I don't know if this is an obsolete way of doing things.</p> <p>based on that angle, I rotate the speed vector to do the bouncing.</p> <p>The piece of code to do the maths is here:</p> <pre><code>static public function newSpeedVector(speedX: Number, speedY: Number, normalAngle: Number): Object{ var vector_angle: Number = Math.atan2(speedY, speedX) * (180/Math.PI); var rotating_angle: Number = (2*(normalAngle - vector_angle) + 180) % 360; var cos_ang: Number = Math.cos(rotating_angle/DEGREES_OF_1RAD); var sin_ang: Number = Math.sin(rotating_angle/DEGREES_OF_1RAD); var final_speedX: Number = speedX * cos_ang - speedY * sin_ang; var final_speedY: Number = speedX * sin_ang + speedY * cos_ang; return {x_speed: final_speedX, y_speed: final_speedY}; } </code></pre> <p>This is how the new speed vector is calculated...</p> <p>My question is, has anyone faced this kind of problem or has some idea on how to avoid this from happening? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload