Automatic gun without keyboard or touch input?


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 =‘Bullet’);
for (var i = 0; i < 50; i++) {
var clone = e.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) {

Shoter.prototype.reset = function (e) {
var pos = this.entity.getPosition();
e.setPosition(pos.x + (Math.random() - 0.5) * this.spread,
pos.z + (Math.random() - 0.5) * this.spread);
e.rigidbody.linearVelocity = pc.Vec3.ZERO;
e.rigidbody.angularVelocity = pc.Vec3.ZERO;

I would like the bullets to have physics but to always aim “forward” where the Gun is pointing. Thanks in advance.


What is the logic for the bullet? Do you give it a velocity when fired? Does it have gravity being applied to it?

There’s another thread with an alternative way dealing with bullet logic here Delay for the shot


Yes, it is useful to add strength to the bullet and grace as a dynamic rigid body, my idea is that the shoter entity shoot a new bullet every second infinitely, without any input method (touch, mouse, keyboard). the bullet could disappear after colliding with something and the impacted entity obtains an imposed according to the impact received.