0
\$\begingroup\$

When increasing my rocketMass from 10 to 1000 or to a 1000 or bringing my shipMass down to 1, I notice very little increase in how far the ship's final inertia is. I'm expecting that increasing from 10 to 1000 will be visibly about 100 times faster.. but it's not. If I multiply the hypotenuse at the end, that does make the bouncing incredibly faster.

Am I misunderstanding physics or is this a calculation error?

handleCollision(r) {
    var angle = r.r * Math.PI / 180.0;
    var rr = this.r * Math.PI / 180;

    var rocketVector = {'x' : r.power * Math.cos(angle), 'y' : r.power * Math.sin(angle)};
    var inertiaVector = {'x' : this.magnitude * Math.cos(rr), 'y' : this.magnitude * Math.sin(rr)};

    var rMass = 100;
    var shipMass = 1;

    var x = (rMass * rocketVector.x) + (shipMass * inertiaVector.x);
    var y = (rMass * rocketVector.y) + (shipMass * inertiaVector.y);
    var xDividedByMass = x / (rMass + shipMass);
    var yDividedByMass = y / (rMass + shipMass);

    var yRadians = (yDividedByMass * Math.PI / 180);
    var xRadians = (xDividedByMass * Math.PI / 180);
    var theta = Math.atan( yRadians / xRadians);

    theta = theta * 180 / Math.PI;
    console.log(theta);

    var hypotenuse = Math.sqrt((xDividedByMass * xDividedByMass) + (yDividedByMass * yDividedByMass));

    if (x < 0) {
        theta -= 180;
    }

    this.r = theta;
    if (this.r < 0) {
        this.r += 360;
    } else if (this.r > 360) {
        this.r -= 360;
    }
}
\$\endgroup\$
  • \$\begingroup\$ Hi, sorry can you confirm something for me, I assume that the input parameter r is the rocket (or whatever is colliding with the ship) but what is the r parameter which is within this i.e. r.r and this.r? \$\endgroup\$ – Malrig Aug 24 '16 at 12:10
  • \$\begingroup\$ Hi sorry for the confusion - r.r is the rotation of the rocket, or the theta of its vector. \$\endgroup\$ – user333866 Aug 24 '16 at 16:50
  • \$\begingroup\$ Hi no worries, it wasn't really important/necessary just got a bit confused \$\endgroup\$ – Malrig Aug 24 '16 at 17:36
0
\$\begingroup\$

I am going to make some assumptions about your program. I am assuming that the rocket is being fired at the ship and then is either destroyed, or becomes stationary.

If this is the case then your problem is occurring due to these lines,

  var xDividedByMass = x / (rMass + shipMass);
  var yDividedByMass = y / (rMass + shipMass);

If the rocket is destroyed or is left stationary then you can ignore its mass here.

This will mean that your ship should gain all the momentum of the rocket and have its speed increased by a lot.


If this is not the case please let me know and I'll take another look.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.