Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my balls disappearing? [closed]

People also ask

Why are my balls staying close to my body?

An overactive muscle causes a testicle to become a retractile testicle. The cremaster muscle is a thin pouch-like muscle in which a testicle rests. When the cremaster muscle contracts, it pulls the testicle up toward the body.

How do you fix a retractile testicle?

In most cases, a retractile testicle does not need to be treated. It will often descend into the scrotum on its own without any medical help. Most cases of retractile testicle will end by the time the boy reaches puberty. A small percentage of retractile testicles can ascend and become undescended testicles.

Why do balls disappear sometimes?

Causes. Each testicle is attached to a muscle called the cremaster muscle. The cremaster muscle can contract inside the body causing the testicle to be pulled in and out of the scrotum; this is called the cremasteric reflex. This is a normal reflex seen in all males.


Your error comes from this line initially:

var direction1 = Math.atan2(ball1.velocitY, ball1.velocityX);

You have ball1.velocitY (which is undefined) instead of ball1.velocityY. So Math.atan2 is giving you NaN, and that NaN value is propagating through all your calculations.

This is not the source of your error, but there is something else that you might want to change on these four lines:

ball1.nextX = (ball1.nextX += ball1.velocityX);
ball1.nextY = (ball1.nextY += ball1.velocityY);
ball2.nextX = (ball2.nextX += ball2.velocityX);
ball2.nextY = (ball2.nextY += ball2.velocityY);

You don't need the extra assignments, and can just use the += operator alone:

ball1.nextX += ball1.velocityX;
ball1.nextY += ball1.velocityY;
ball2.nextX += ball2.velocityX;
ball2.nextY += ball2.velocityY;

There's an error in the collideBalls function:

var direction1 = Math.atan2(ball1.velocitY, ball1.velocityX);

It should be:

var direction1 = Math.atan2(ball1.velocityY, ball1.velocityX);