I have a gun for my FPS game but it cant shoot

Before i get started i have been working on all the little things, like movement but i also need a few more things… i need the gun to stick to the player, i need to need to let the player move forward, i also need the player to be able to jump

Hi @Aviel_Rodriguez,

You can add the gun entity as a child to the player, and it will follow him around.

For jumping search in the forums, you will find a lot of threads on the subject. Like this:

Can i just let you in on the code and you help me from there? when i try going into the debug mode it says model not found. also, the movement will not work unless you are pressing a or d…

Yes, if you can share a url of your public project or if it’s private add me: leonidas

i have added you for now.

1 Like

So, the code you have inside the gun.js script is outside of any script component method, so it fails. At the moment it executes the Playcanvas application hasn’t finished initializing:

You should move any entity related code inside the initialize method of the script:

// initialize code called once per entity
Gun.prototype.initialize = function() {
   // here
};    

Furthermore, instead of creating entities and loading assets in code, you can do the same by creating the entities in editor. To use them you can use script attributes to get a reference to them.

I would start studying the following manual section on scripting and then studying some of the examples available:

https://developer.playcanvas.com/en/user-manual/scripting/script-attributes/

https://developer.playcanvas.com/en/tutorials/first-person-movement/

https://developer.playcanvas.com/en/tutorials/third-person-controller/