Even more questions

Hi again all,

From now on, I’ll keep all my questions in here to save from filling the forum with lots and lots of different things.

Todays question(s) relate to manipulating a (grand)child object.

I have set up

Entity
    -Child Entity
        -Grandchild entity

I have my player control script added to the Parent Entity and everything is working okay.

What I need to figure out is how to rotate the Grandchild entity from within the Parent Entity script.

The problems are, I don’t know (well I’m pretty sure I haven’t) if I’ve called the Grandchild correctly, and I seem to be getting tripped up between when to use…

var something = app.root.findByName();

and

this.something = app.root.findByName();

There is the possibility that I’m going about it completely the wrong way, I did think that using a quaternion rotation value instead of euler would be easier, and probably more efficient, but I’m completely lost when it comes to those, so I went this way.

The second problem is that I’m not sure how to get the grandchild object to rotate back to it original position when the player releases the corresponding key, but that’s another thing for another time I think. :smile:

So, could anyone point me in the right direction to fixing this? :smile:

Thanks
TheMightySpud

Latest Build Here

Engine Rotation code commented out so that the thing runs. :slight_smile:

Moved on from the engine rotation problem for a while to investigate sprite sheets and have more or less successfully applied one to the player ship weapons fire.

One small problem, I’m using the

app.mouse.isPressed(pc.input.MOUSEBUTTON_LEFT)

method to fire the thing, and I can’t get it to turn off.

I did find this

Answer with the problem I mentioned

But I’m not sure I get it…

I’ve updated the code to what I think is the new way of doing it based on other updates to the api that I’ve seen, but I get thrown an error ‘Unable to Load Scripts’

This is what I’ve changed it to, and I’ve added it into the first script that loads on my ‘root’ in the Initialise Function.

app.mouse = new pc.input.Mouse(window);

And here is the full code for my Muzzle Flashes Entity

pc.script.create('muzzleFlashes', function (app) {
    // Creates a new MuzzleFlashes instance
    var MuzzleFlashes = function (entity) {
        this.entity = entity;

        //app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
        //app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);
        
    };

    MuzzleFlashes.prototype = {
        // Called once after all resources are loaded and before the first update
        initialize: function () {

            var muzzleEntity = app.root.findByName("Player_MuzzleFlashes");

            this.muzzleOffsetx = 0.0;
            this.muzzleOffsety = 0.75;

            this.muzzleOpacity = 0;
            this.muzzleMaterial = muzzleEntity.model.model.getMaterials()[0];
            this.muzzleMaterial.opacity = this.muzzleOpacity;
            this.muzzleMaterial.diffuseMapTiling = new pc.Vec2(0.25, 0.25);
            this.muzzleMaterial.diffuseMapOffset = new pc.Vec2(0.0, 0.75);
            this.muzzleMaterial.update();
            
        },

        // Called every frame, dt is time in seconds since last update
        update: function (dt) {
             if (app.mouse.isPressed(pc.input.MOUSEBUTTON_LEFT)) {

                this.muzzleOpacity = 1;

                var muzzleEntity = app.root.findByName("Player_MuzzleFlashes");
                this.muzzleMaterial = muzzleEntity.model.model.getMaterials()[0];
                this.muzzleMaterial.opacity = this.muzzleOpacity;
            
                if (this.muzzleOffsetx < 0.75) {
                    this.muzzleOffsetx = this.muzzleOffsetx + 0.25;
                } else {
                    this.muzzleOffsetx = 0.0;
                    this.muzzleOffsety = this.muzzleOffsety - 0.25;
             }
                 
                 
             }
            
            this.muzzleMaterial.diffuseMapOffset = new pc.Vec2(this.muzzleOffsetx, this.muzzleOffsety);

            this.muzzleMaterial.update();
        }
    };

    return MuzzleFlashes;
});

So, just looking at a quick point or push in the right direction so I can figure these things out :smile:

Thanks
TheMightySpud

Ignore everything about the sprite object not turning off, I was being an idiot. Now fixed :slight_smile: