Make Enemy Projectiles Spawn with Enemy Player

PlayCanvas 3D HTML5 Game Engine - Game
PlayCanvas | HTML5 Game Engine - Editor

The projectile spawns but I don’t know how to make it spawn in front of the Enemy Player. I want it to look like the Enemy is shooting at the player. Everything can be found in level one.

var Enemylaser = pc.createScript('enemylaser');

// initialize code called once per entity
Enemylaser.prototype.initialize = function () {

};

// update code called every frame
Enemylaser.prototype.update = function (dt) {

    var templateAsset = this.app.assets.find("EnemyLaser");
    var instance = templateAsset.resource.instantiate();
    var position = this.entity.getPosition();

    var entity = new pc.Entity();
    this.app.root.addChild(entity);

    entity.translate(position.x - 0.01, position.y, position.z);
    entity.addChild(instance);


};

// swap method called for script hot-reloading
// inherit your script state here
// Enemylaser.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/

@Vapor_Trout You will have to move the projectiles to in front of what is firing it.

1 Like

Oh makes since, let me see if it works.

when i moved it to the front, it stop spawning, it just floats there.

Which entity in your project has this script? It is unclear to me what is the difference between a projectile and a laser in your project.

It sounds like you add it to your scene but you don’t move the projectile/laser forward with a script.

1 Like

Enemy Laser, I made a new scene named Testing(enemylaser). The projectile script was from someone else in the group.