no errors just not working
Code:
var BowlingBallVontroller = pc.createScript('bowlingBallController');
// initialize code called once per entity
BowlingBallController.prototype.initialize = function() {
var BallScript = pc.createScript('ballScript');
BallScript.attributes.add('speed',
{
type: 'number',default: -8 });
BallScript.prototype.initialize = function()
{
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
this.app.keyboard.on('keydown', this.onKeyDown, this);
var pins = this.app.root.findByTag("Pin");
this.startingPositions = [];
this.startingRotations = [];
for(var i = 0; i < pins.length; i++)
{
this.startingPositions.push(pins[i].getLocalPosition().clone());
this.startingRotations.push(pins[i].getLocalRotation().clone());
}
this.ballPosition = this.app.root.findByName("BowlingBall").getLocalPosition().clone();
this.ballMoving = false; };
BallScript.prototype.onCollisionStart = function (result)
{
if (result.other.rigidbody)
{
if(result.other.name == "BowlingPin")
this.entity.sound.play("Hit");
}
};
BallScript.prototype.onKeyDown = function(e) { if(e.key == pc.KEY_SPACE || e.key == pc.KEY_W)
{ this.entity.rigidbody.applyImpulse(0,0, this.speed); this.ballMoving = true; }
};
if(e.key == pc.KEY_R)
{ var pins = this.app.root.findByTag("pin");
for(var i = 0; i < pins.length; i++)
{
pins[i].rigidbody.teleport(this.startingPositions[i],this.startingRotations[i]);
pins[i].rigidbody.linearVelocity = pc.Vec3.ZERO;
pins[i].rigidbody.angularVelocity = pc.Vec3.ZERO;
} // now the ball this.entity.rigidbody.teleport(this.ballPosition); this.entity.rigidbody.linearVelocity = pc.Vec3.ZERO; this.entity.rigidbody.angularVelocity = pc.Vec3.ZERO; this.ballMoving = false; } if(e.key == pc.KEY_B){ // Just the ball this.entity.rigidbody.teleport(this.ballPosition); this.entity.rigidbody.linearVelocity = pc.Vec3.ZERO; this.entity.rigidbody.angularVelocity = pc.Vec3.ZERO; this.ballMoving = false; } if(e.key == pc.KEY_LEFT || e.key == pc.KEY_A){ this.entity.rigidbody.applyImpulse(-0.2,0,0); } if(e.key == pc.KEY_RIGHT || e.key == pc.KEY_D){ this.entity.rigidbody.applyImpulse(0.2,0,0); } }; // update code called every frame BallScript.prototype.update = function(dt) { };
}
};
// update code called every frame
BowlingBallController.prototype.update = function(dt) {
};
// swap method called for script hot-reloading
// inherit your script state here
// BowlingBallVontroller.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/