Help with rotations

Godot Version

Godot_V.4.3

Question

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

maybe you must use global_rotation?

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

Yes i have i just missed thee $ simbol

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.

i used the global_rotation and still dont work, i printed the sprtie2D global_rotation and bullet global_rotation and it is the same.

What about it doesn’t work? Can you share an example? Are your sprites right-facing?

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

Could you post a screenshot? You mention a mouse position but I don’t see that in the pasted code.

0° in games is facing right, so maybe there is a language disconnect too.


This is a pic of tank

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.

1 Like

Actually that seems to work just fine.Thanks for helping out!