Its a bit hard to explain, but i will try my best, i have a tank and a bullet,i added the func for shoot,when func shoot is called the bullet isnt going in the direction, and the rotation is wrong.In the tank i have a Sprite2d and the marker2d for the spawn point for the bullet.The script for the shoot func is:
func shoot():
if Input.is_action_just_pressed(“shoot”):
var bullet = BULLET.instantiate()
bullet.global_position = $Marker2D.global_position
bullet.rotation = Sprite2D.rotation
get_parent().add_child(bullet)
Script for the bullet is:
var speed = 1500
func _physics_process(delta: float) → void:
position += speed * delta * transform.x
Do you have a variable named Sprite2D? Because it is shadowing the class Sprite2D if so, might be better to rename that variable or if you are trying to get a node named “Sprite2D” then use the dollar sign as $Sprite2D
Ah, if you recieve an error in your code make sure to paste the error as well. Also properly formatting the code will make it easier for those helping to read.
The sprite2D rotation is equal to mouse position and when i shoot bullet is spawnig in the right place but isnt going in the direction of the mouse,
and Sprites arent facing right, they are facing forward
Your tank is off-center, try moving the visual and collision elements toward (0, 0) where the y and x axis intersect. The sprite is also facing UP not RIGHT, so it’s rotation will be off as I mentioned before; the bullet scene should follow the same advice.