Top down shooter bullet mechanic.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Spectralniy

I want to make the same bullet mechanic as in this video
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.

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.

klaas | 2021-07-22 20:15

:bust_in_silhouette: Reply From: lewis glasgow
#player shoot code
func _ready():
	var bullet = preload("bullet path").instance()
	bullet.global_position = $muzzle.global_postiton

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

It says “Invalid call. Nonexistent function ‘set_as_toplevel’ in base ‘PackedScene’.”

Spectralniy | 2021-07-23 09:57

var bullet = preload("res://bullet.tscn").instance()
bullet.global_position = global_position

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

lewis glasgow | 2021-07-23 10:44

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

Player code
Bullet code

Spectralniy | 2021-07-23 14:01

var bullet = preload("res://bullet.tscn").instance()
		bullet.global_position = position

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

lewis glasgow | 2021-07-24 16:04