How to rotate particle 2d

Godot Version



<i would appreciate if you could teach me how to rotate particle 2d in a way I want. right now, with my code, hit effect somehow appears upside down.

func knock_back(source_position: Vector2) -> void:
	hit_effect.rotation = get_angle_to(source_position)


try rotate it 180deg

func knock_back(source_position: Vector2) -> void:
	hit_effect.rotation = 180 + get_angle_to(source_position)

that still did not solve the problem. particle still appears at downside when bullet hit upper side

you will need to check who is the node2d’s position the get_angle_to method based to and what actually the source_position is to know what’s wrong
also since it’s in radian try change to

hit_effect.rotation = PI/2.0+get_angle_to(source_position)
1 Like

What do you want to happen? particles are currently rotating towards the center of the object they hit, do you want them rotated away from the center or rotated to keep the projectiles velocity i.e. moving in the same direction as the bullet?

I want to make particle appear at upward when bullet hit upper side and downward when hit down side.
Im following this tutorial.

class_name HurtBox
extends Area2D

func _ready() -> void:
	connect("area_entered", Callable(self, "_on_area_entered"))

func _on_area_entered(hitbox: HitBox) -> void:
	if owner.has_method("knock_back"):

The posted tutorial is + 180° which seems off to me. It’s also for sword/melee effects?

hit_effect.rotation = PI + get_angle_to(source_position)

I would just use the projectile’s rotation, replacing source_position: Vector2 with source_rotation: float

if I replaced it with source_position: float, how would I rotate it?

By passing in hitbox.rotation instead of hitbox.global_position

i get error for get_angle_to when I replaced it with float.
I ended up achieving what i want by setting the scale of particle xy to negative1 and

hit_effect.rotation = PI*2 - get_angle_to(source_position)

I really dont understand what PI does.

My full recommendation would look like so.

func knock_back(source_rotation: float) -> void:
	hit_effect.rotation = source_rotation

get_angle_to and rotation are both in radians, a 180° turn is equal to PI. they recommended you rotate it by 90° or PI/2 radians.PI*2 would be a full 360° turn for no change, you just have

hit_effect.rotation = -get_angle_to(source_position)

for the same result.

scaling Y by negative one is a great solution!

okay, i think i am starting to understand what im doing maybe…
which way do you think is better? play particle which is a child of enemy or instantiating particle.

btw, if im going to instantiate the particle, how do you inverse it? simply changing the scale didnt inverse the particle.

func _on_bullethitbox_area_entered(area):
	if area.is_in_group("enemies"):
		air_impact = false
		wall_impact = false
		var hit_impact = hitimpactScene.instantiate()
		hit_impact.global_position = self.get_position()

never mind, i could simply do = rotation