Godot Version
4
Question
i have the gun working but right now its more like a 3d print becase it cant shoot idk how to fix it.
4
i have the gun working but right now its more like a 3d print becase it cant shoot idk how to fix it.
So i guess you are spawning bullets, but they arent moving?
This would mean you have to give them a velocity in the direction you want them to fly
no idk how to spawn the bullets
but im working with a tutoryal now
well if you need help it would be good to know what exactly you have and what you want to achieve
So i have ot so it will spawn bullets but when i hit the right mousse button (i thought it was just the left button so i swaped it) instead of firering it minimizes the game. And i accidentally closed the page so idk if its just outdated code
Can you show your code?
extends Area2D
var speed = 750
func physics_process(delta):
position += transform.x * speed * delta
func on_Bullet_body_entered(body):
if body.is_in_group(“mobs”):
body.queue_free()
queue_free()
var _blast:PackedScene
if Input.is_action_just_pressed("Blast"):
shoot()
func shoot():
var b = shoot().instantiate()
owner.add_child(b)
b.transform = $Muzzle.transform
func blast():
var b = blast().instantiate()
owner.add_child(b)
b.transform = $Muzzle.global_transform
if Input.is_action_just_pressed("Blast"):
shoot()
func B():
var b = blast().instantiate()
add_child(b)
b.transform = $Muzzle.transform
func b():
var b = blast().instantiate()
owner.add_child(b)
b.transform = $Muzzle.global_transform
this dident show the indents/errors so its not the best showing
remove the “transform.x” from “position += transform.x * speed * delta”, so it looks like this:
position += speed * delta
Whats missing is the direction of the bullet. is your game topdown or a sidescroller?
the bulets still wont spawn heres the code again, its a bit difrant
extends Area2D
var speed = 750
func physics_process(delta):
position += speed * delta
func on_Bullet_body_entered(body):
if body.is_in_group(“mobs”):
body.queue_free()
queue_free()
var _blast:PackedScene
if Input.is_action_just_pressed("Blast"):
blast()
var b = blast().instantiate()
owner.add_child(b)
b.transform = $Muzzle.transform
func blast():
var b = blast().instantiate()
owner.add_child(b)
b.transform = $Muzzle.global_transform
if Input.is_action_just_pressed("Blast"):
blast()
func B():
var b = blast().instantiate()
add_child(b)
b.transform = $Muzzle.transform
func b():
var b = blast().instantiate()
owner.add_child(b)
b.transform = $Muzzle.global_transform
you need to set the value of blast to the packed scene:
var _blast: PackedScene = load("Path/to/the/bullet_scene.tscn")
replace the string inside of the “load()” method with the path to your bullet_scene by dragging it in there from the file-system