Note that there are some explanatory texts on larger screens.

plurals
  1. POAS3 Collision response for a game
    primarykey
    data
    text
    <p>I hav bee struggling with a collision response method, im writing in <em>actionscript 3</em>, for a long time now, and I am hoping someone can explain what this code means, for I have only modified it. I did not write it from scratch. also I am using the Collision Detection Toolkit to find where the collisions are happening.<br> What im trying to do is make it so that Ball (which is the object that you move around the screen with your keyboard) hit's a wall or object it will not go through the wall or object. </p> <p>my understanding of this is that you are finding the angle that the collision is happening at and then you need to find the angle which is adjacent which is the new vector and push back the object by however much it's overlapping, but I dont understand how this function works for instance what is </p> <pre><code>vx0:Number = ball.vx * cos + ball.vy * sin; </code></pre> <p>finding?. in addition I dont want the ball to accelerate I want it's velocity to be constant until it hits an object. also would it be faster to search through this array backwards? </p> <p>-- I appreciate any one who takes the time to try and help me with this, and im sorry if I have some misspellings. </p> <pre><code> for(i = 0; i &lt; collisions.length; i++) { var collision:Object = collisions[i]; var angle:Number = collision.angle; var overlap:int = collision.overlapping.length; var ball:Ball = collision.object1; var sin:Number = Math.sin(angle); var cos:Number = Math.cos(angle); var vx0:Number = ball.vx * cos + ball.vy * sin; var vy0:Number = ball.vy * cos - ball.vx * sin; vx0 = .4; ball.vx = vx0 * cos - vy0 * sin; ball.vy = vy0 * cos + vx0 * sin; ball.vx -= cos * overlap / ball.radius; ball.vy -= sin * overlap / ball.radius; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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