Coding gone wrong

hay this all i want is code to make bullet examle when mouse pressed clone then wait 0.01 sec then fire in the direction im looken at and after a while it stops deleates its self to stop lag

my code pls fix bullet is bad i try do it for my game bullet here is the code try fix make it like working bullet what i said

this.onKeyPress("mouse", function () {
    for (var _repeatIdx1=0; _repeatIdx1<1000; _repeatIdx1++) {

also im just like 10 yrs is that why im bad at code

anything wrong tho with the code

To fire a bullet when you click the mouse you can add a new script with the name “mouse” to your player entity and replace the code with the code below.

var Mouse = pc.createScript('mouse');

// initialize code called once per entity
Mouse.prototype.initialize = function() {, this.onMouseDown, this);

Mouse.prototype.onMouseDown = function (event) {
    if (event.button === pc.MOUSEBUTTON_LEFT) {
        var bullet ='Bullet').clone();;
        bullet.enabled = true;

To make this work you need an entity with the name “Bullet”. Add a new script with name “bullet” and replace te code with the code below. Add also a collision and rigidbody component. Set the rigidbody type to kinematic. If you want you can also add a sphere model, otherwise you can’t see the bullet.

var Bullet = pc.createScript('bullet');

// initialize code called once per entity
Bullet.prototype.initialize = function() {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this); 
    this.entity.collision.on('collisionend', this.onCollisionEnd, this);

// update code called every frame
Bullet.prototype.update = function(dt) {
    if (this.entity.enabled === true) {
        }.bind(this), 3000);

Bullet.prototype.onCollisionStart = function (result) {
    if (result.other) {

I expect that some adjustments are needed to get the desired result. You can also use the scripts as an example and do it your own way.

Please don’t multipost @Jesse_Gagne. Just edit your most recently post please