How to keep Sprite3D stationary relative to the Camera

Godot Version

v4.2.2.stable.official

Question

Hi Community,
I am working on a 3D game that is using many Sprite 3D nodes.

I’ve encountered an issue where a ‘Pow’ ‘particle’ effect, which is a Sprite3D node (billboard disabled), moves with the camera instead of staying fixed in the world space. The camera is attached to the player and the Sprite3D node is set to default properties.

Below is the code snippet for the ‘Pow’-Sprite:

@onready var PowText: Sprite3D = $PowText

func _ready() -> void:
	
	var final_scale = randf_range(0.8,0.9)
	var random_rotation = randi_range(-180, 180)
	var random_disappear_time:float = randf_range(0.12, 0.22)
	
	global_rotation_degrees = Vector3(0,0,random_rotation)
	PowText.rotation_degrees.z = -global_rotation_degrees.z
	
	transparency = 1.0
	scale = Vector3.ONE * 0.5
	
	var tween = get_tree().create_tween()
	tween.tween_property(self, "scale", final_scale*Vector3.ONE, 0.08)
	tween.tween_property(self, "transparency", 0, 0.08)
	await tween.finished
	
	var tween2 = get_tree().create_tween()
	tween2.tween_property(self, "scale", 0.3*Vector3.ONE, random_disappear_time)
	tween2.tween_property(self, "transparency", 1.0, random_disappear_time)
	await tween2.finished
	
	queue_free()

Could anyone advise on how to ensure the ‘Pow’ particle remains in place regardless of camera movement?

If I can provide more needed information, please let me know!

Have you tried setting your Sprite3D’s TopLevel setting to true?

# Code example
top_level = true

This will make the node ignore any transformations that are otherwise applied from the node hierarchy (e.g. the camera or player node).

Note: Saying that an object should be stationary relative to something else (like your title) is the opposite of what you’re actually trying to achieve; making the object stationary in world space. It made me slightly confused.

EDIT: The created particle was a child of the player with the camera…
Conclusion: Never forget your get_parent()!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.