The bullet doesn't flip with player direction

Godot Version

Godot 4.3

Question

When the player is flipped, the bullet does not flip with him. When shooting!

What is the code to make the bullet flip with the player’s direction?

And where should i put that code

In the Area2D bullet script
Or in the player Script?

can you show the code where you create the bullet?

1 Like
extends Area2D


@export var speed = 750

func _physics_process(delta):
	position += transform.x * speed * delta


func _on_body_entered(body: Node2D) -> void:
	if body.has_method("enemy_hit"):
		body.enemy_hit()
		queue_free()

func _on_despawntimer_timeout() -> void:
	queue_free()

Since you are using transform.x you could rotate the bullet, or scale the bullet by -1.0 on the x axis to flip it’s movement.

2 Likes

How to do that in the Area2D script ?

So, when my player Flip I want the Bullet to flip automatically too when shooting

The Area2D script knows nothing of the player, so it cannot currently retrieve the player’s scale or rotation when instantiated.

It would be better to apply this transform when spawning the bullet from the player script.

1 Like