Hi. I try to make a Gun in Augmented Reality But I want to eliminate the use of the Mouse or Touch keyboard. Could you suggest me some script that triggers an entity (with physics of course) every second? I tried to use this script but it makes Bullet always go down, regardless of the rotation of the shoter.
var Shoter = pc.createScript’(shoter’);
Shoter.attributes.add(‘spread’, {
type: ‘number’,
default: 10,
title: ‘Spread’
});
// initialize code called once per entity
Shoter.prototype.initialize = function() {
this.entities = [];
var e = this.app.root.findByName(‘Bullet’);
for (var i = 0; i < 50; i++) {
var clone = e.clone();
this.app.root.addChild(clone);
this.entities.push(clone);
this.reset(clone);
}
};
// update code called every frame
Shoter.prototype.update = function(dt) {
for (var i = 0; i < this.entities.length; i++) {
var e = this.entities[i];
var pos = e.getPosition();
if (pos.y < -10) {
this.reset(e);
}
}
};
Shoter.prototype.reset = function (e) {
var pos = this.entity.getPosition();
e.setPosition(pos.x + (Math.random() - 0.5) * this.spread,
pos.y,
pos.z + (Math.random() - 0.5) * this.spread);
e.rigidbody.linearVelocity = pc.Vec3.ZERO;
e.rigidbody.angularVelocity = pc.Vec3.ZERO;
e.rigidbody.syncEntityToBody();
};
I would like the bullets to have physics but to always aim “forward” where the Gun is pointing. Thanks in advance.