0 votes

I want to make the same bullet mechanic as in this video https://youtu.be/HycyFNQfqI0
but without rotating the player. I need bullets to just head towards the mouse cursor, just like in Enter the gungeon. How do I make it?

I just changed the engine from GMS2 to Godot, so sorry for the stupid question.

Godot version 3.3.2
in Engine by (12 points)

Hi,
your question isnt stupid but very vague! You do not present us any code or show us any specific proplem you have with your code.

1 Answer

+1 vote
#player shoot code
func _ready():
    var bullet = preload("bullet path").instance()
    bullet.set_as_toplevel(true)
    bullet.look_at(get_global_mouse_position())
    bullet.global_position = $muzzle.global_postiton
    $muzzle.add_child(bullet)

#this is for the bullet
func _process(delta):
    position -= global_transform.x*speed
    #towords its local x axis
by (266 points)

It says "Invalid call. Nonexistent function 'setastoplevel' in base 'PackedScene'."

var bullet = preload("res://bullet.tscn").instance()
add_child(bullet)
bullet.set_as_toplevel(true)
bullet.global_position = global_position
bullet.look_at(get_global_mouse_position())

did you include.instance()this makes the scene an actual object

Yes, i forgot to .instance() it.
The game now doesn't crash, but it works.. well.. really weird.

Player code
Bullet code

var bullet = preload("res://bullet.tscn").instance()
        bullet.set_as_toplevel(true)
        bullet.global_position = position
        add_child(bullet)
        bullet.look_at(get_global_mouse_position())

it has to be in this order otherwise and for the bullet position += transform.x*speed

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.