`im trying to simulate the sonic losing rings when got hit or got in spike ok it worked but there is a really small problem that didnt figured it out it is the scale of the rings that get as packed scene and child node i want to make there scales is smaller and this what i did with no affect i tryied to print the scale and it print the scale that i want but in game nothing has changed it still big
#this is my code
extends Node3D
var score = 0
@export var ring_with_gravity_scene :PackedScene
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
$Soinc_classic/SonicGui/Node2D/RINGS_CHANGEABLE.text = str(Globals.rings)
if Globals.sonic_got_hurt :
if Globals.rings>0:
$lost_ring.play()
for i in range(Globals.rings):
var ring = ring_with_gravity_scene.instantiate()
ring.global_position = $Soinc_classic.global_position + Vector3(0, 5, 0)
get_tree().current_scene.add_child(ring)
ring.scale *= 0.5
var impulse = Vector3(
randf_range(-17.0, 17.0),
randf_range(4.0, 6.0),
randf_range(-17.0, 17.0)
)
print(ring.scale)
ring.get_node("RigidBody3D").apply_impulse(impulse, Vector3(randi_range(-1,1),randi_range(-1,1),randi_range(-1,1)))
else:
$death_hurt.play()
Globals.rings = 0
Globals.sonic_got_hurt = false
(I have no frame of reference to Sonic so I am assuming you want progressively smaller rings)
You are instancing a new ring every iteration of the loop.
Each of those gets hit with the .5 scale but it isn’t progressive.
For example lets say the ring starts out at size 20.
You instance a ring with size 20 and *=.5 so that ring size is 10.
When you instance the next ring its size is 20 so that ring size will end up 10 as well.
You need to keep track of the previous rings scale (or size) and *= that number by .5 and apply that scale to the next ring.
Again, this is assuming that each ring is supposed to be smaller than the last.
Rigid bodies generally do not like to be scaled. try scaling specifically the visual component such as the mesh instance(s) assuming they are a child of the rigid body.
As sancho2 has stated your ring will only scale once, you may want to use a tween.
var scale_tween := create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_QUAD)
scale_tween.tween_property(ring.get_node("RigidBody3D/Visual"), "scale", Vector3.ZERO, 1.0)
Another good bit of advice is to use signals instead of checking Globals.sonic_got_hurt every frame through _process, basically where ever you set sonic_got_hurt you should spawn rings instead.