Add tunneling handling to pitching.js

This commit is contained in:
Ryan Huffman 2015-10-27 15:35:30 -07:00
parent 779cadd5bd
commit e9a2e91374

View file

@ -270,6 +270,18 @@ Baseball.prototype = {
if (name == "Bat") {
if (this.state == BASEBALL_STATE.PITCHING) {
print("HIT");
var yaw = Math.atan2(myVelocity.x, myVelocity.z) * 180 / Math.PI;
var foul = yaw > -135 && yaw < 135;
if (foul && myVelocity.z > 0) {
var xzDist = Math.sqrt(myVelocity.x * myVelocity.x + myVelocity.z * myVelocity.z);
var pitch = Math.atan2(myVelocity.y, xzDist) * 180 / Math.PI;
print("Pitch: ", pitch);
if (Math.abs(pitch) < 15) {
print("Reversing hit");
myVelocity.z *= -1;
}
}
// Update ball velocity
Entities.editEntity(self.entityID, {
@ -293,8 +305,6 @@ Baseball.prototype = {
volume: 1.0
});
}, 500);
var yaw = Math.atan2(myVelocity.x, myVelocity.z) * 180 / Math.PI;
var foul = yaw > -135 && yaw < 135;
if (foul) {
print("FOUL ", yaw)
this.state = BASEBALL_STATE.FOUL;