when i put the rigidbody.teleport
function in the setTimeout function, it doesn’t work. see code.
var Shoot = pc.createScript('shoot');
Shoot.attributes.add('guPoint', {type: 'entity'});
Shoot.attributes.add('bullet', { type: 'entity' });
// initialize code called once per entity
Shoot.prototype.initialize = function() {
};
// update code called every frame
Shoot.prototype.update = function(dt) {
// Press X to shoot
if(this.app.mouse.wasPressed(pc.MOUSEBUTTON_LEFT)) {
this.shoot();
}
};
Shoot.prototype.shoot = function(){
var gp = this.guPoint.getPosition();
this.bullet.rigidbody.applyImpulse(0,5,0);
setTimeout(function(){
this.bullet.setPosition(gp);
},1000);
};
// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/
it works without setTimeout. But i need it for one second then teleport back to the gun point. pls help and fix this glitch.