How would i make a functioning gun

How would i make a gun and when the player holds down rmb it shoots?

Hi @plok_cxz,

There isn’t any ready made tutorial to see this in action. As a short summary of the steps you need to build this:

  • To have your player hold a gun:
  1. If you are doing a First Person Shooter, add the gun as a child to the camera.
  2. If you are doing a Third Person Controller, add the gun as child to one of the bones of the character’s model.
  • To shoot you will have to study how to create projectiles: fast moving objects that travel from the player to the direction the gun is pointing to.

Trying searching the forum with keywords like gun, first person shooter etc.

3 Likes

also how would i limit looking up and down

1 Like

You will have to add some constraints on your camera script, to check the up/down angle and stop rotation.

1 Like

what would the rmb be labeled as?(like right left etc;)

1 Like

https://developer.playcanvas.com/en/tutorials/mouse-input/

The developer documentation does have a decent search feature for this kind of stuff.

1 Like

https://playcanvas.com/editor/scene/1360663
here is my game how can i make the gun rotate with the player?

1 Like

Hi @SLAVRED0000N4SIR! You can make the gun entity a child of your player entity.

2 Likes

i have already done that. how would i be able to rotate it around a player.

What do you mean with ‘rotate it around the player’? Do you have an example?

https://launch.playcanvas.com/919035?debug=true
where the gun look’s into the direction the player is facing.
this is the issue here:PlayCanvas | HTML5 Game Engine

if you do not see the gun when you spawn. look around and you will find it.

Sorry, it has to be a child entity of your camera entity. :upside_down_face:

how can i do that?

Drag and drop your gun entity into your camera entity.