#How do I make bullets shoot out of my player

40 messages · Page 1 of 1 (latest)

crude tree
#

I have movement code and the player points at the mouse. But I don't know how to make bullets shoot out of the player.

primal junco
#

Do you have a bullet scene?

#

I would start with making one

crude tree
#

okay

#

but i've been confused on what node i should use

primal junco
crude tree
#

okay

crude tree
#

what do i do now

primal junco
crude tree
#

yes

#

and shooting them

primal junco
#

You’ll need a preload variable in your player scene. This is a reference to the bullet

var bullet_scene = preload(PATH TO BULLET SCENE)

#

then you can create a new function, maybe call it shoot_bullet()

#

In that function you have to instantiate the bullet scene and add it to the world.


get_parent().add_child(instance)

instance.global_position = global_position 
instance.look_at(get_global_mouse_position) ```
#

This will spawn the bullet where the player is and make the bullet look at the mouse

crude tree
#

it gave me this error

primal junco
#

It’s a function 😄

crude tree
#

oh

crude tree
#

What about shooting

primal junco
crude tree
#

No I mean like how does the bullet shoot

tardy cliff
#

You have to make the bullet move the same way you made the player move

crude tree
#

How do I do that

#

All I did was push the position

primal junco
crude tree
#

Nope

#

As in right I have no code

primal junco
#

You’d need some movement code for the bullet then

crude tree
#

How

primal junco
#

The bullet doesn’t have to do more than go in a straight line

#

Global_position += global_transform.x * delta * 100 for example should work

crude tree
#

I have one game

#

It doesn't wotk

#

It says invalid operands 'Vector2' and 'Transform2D' in operator '+'

crude tree
#

nvm

#

i forgot the .x

#

i guess thats it

#

thank you