[SOLVED] How do I make a gun shoot, reload, and show magazine

whers is that

why is it 15 different code

Start on top of your script and look for the word initialize. You can also use the search function of the code editor.

They are different functions. This is necessary for the script to function properly and to organize things properly.

but i said WHERE

1 Like

No need to shout or be demanding. Someone is trying to help you in their free time. Please be patient.

sorry

im sorry

I see you have renamed your script or some functions. Make sure that everthing has the same name.

i see, where do i put this

    this.rounds = 12;

    if (this.app.mouse) {
        this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
        this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);
        this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
    }

what line do i put it on or do i put it anywhere

After line 42.

sweet

// initialize code called once per entity
FirstPersonMovement.prototyp.initialize = function() {
    this.force = new pc.Vec3();
    this.eulers = new pc.Vec3();

    var app = this.app;

    // Listen for mouse move events
    app.mouse.on("mousemove", this._onMouseMove, this);

    // when the mouse is clicked hide the cursor
    app.mouse.on("mousedown", function () {
        app.mouse.enablePointerLock();
    }, this);

    // Check for required components
    if (!this.entity.collision) {
        console.error("First Person Movement script needs to have a 'collision' component");
    }

    if (!this.entity.rigidbody || this.entity.rigidbody.type !== pc.BODYTYPE_DYNAMIC) {
        console.error("First Person Movement script needs to have a DYNAMIC 'rigidbody' component");
    }
    rounds = 12;

if (this.app.mouse) {
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);
this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
}
};

// update code called every frame
FirstPersonMovement.prototype.update = function(dt) {
    // If a camera isn't assigned from the Editor, create one
    if (!this.camera) {
        this._createCamera();
    }

    var force = this.force;
    var app = this.app;

    // Get camera directions to determine movement directions
    var forward = this.camera.forward;
    var right = this.camera.right;


    // movement
    var x = 0;
    var z = 0;

    // Use W-A-S-D keys to move player
    // Check for key presses
    if (app.keyboard.isPressed(pc.KEY_A) || app.keyboard.isPressed(pc.KEY_Q)) {
        x -= right.x;
        z -= right.z;
    }

    if (app.keyboard.isPressed(pc.KEY_D)) {
        x += right.x;
        z += right.z;
    }

    if (app.keyboard.isPressed(pc.KEY_W)) {
        x += forward.x;
        z += forward.z;
    }

    if (app.keyboard.isPressed(pc.KEY_S)) {
        x -= forward.x;
        z -= forward.z;
    }

    // use direction from keypresses to apply a force to the character
    if (x !== 0 && z !== 0) {
        force.set(x, 0, z).normalize().scale(this.power);
        this.entity.rigidbody.applyForce(force);
    }


Thats what it says and i dont know what that means

what does this mean?


its says this after i saved it

Probably because you changed partly the scriptname during this process. If you add me to the project I will try to fix this.

thats not all of the code thi

THANK YOU SOO MUCH FOR THIS!!! you are the best

You’re welcome. For the next time you want to add code, place it between the symbols of the code highlight function.

image

1 Like

I have fixed some problems in your project. Shooting now works fine and you can reload with the R key as you wish. I saw you have huge zip and rar files in your project. I think you better delete these files from your project to save storage and a get a better loading time. For now I have disabled the preload option so your loading time is better.

if i wished for the bullet to go faster, how will I do that

lets say i soot north, then i look west, the bulet will move with my cusor from north to west

I changed the speed a bit. I don’t know what you mean by the other.

The bullet won’t continue going north when I look west

Like when you do a flick, the bullet hits the guy while you already look forward, but you can’t do that because the bullet will still be going towards the crosshairs, it’s hard to explain