Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Halfmania33 |
Hi everyone,
i’m trying to animate a Polygon2D shape (over 600 vertices) with a tween animation by code.
The polygon2D shape is generated dynamically with GDScript. And everytime i generate a new set of coordinates for its vertices (the next shape), i want the transition between the old and the new shape to be smooth.
So i thought tweening would be the solution to do it dynamically with GDScript. But it seems that doesn’t work.
If i just update the polygon2D with the new set of vertices coordinates, it works perfectly but it’s instantaneous (without transition/animation).
Below, some code i tested with no result :
onready var currentPoly = Polygon2D.new()
var morphingSpeed = 0.5
var morphingSpeed2 = 0.05
func _ready() -> void:
currentPoly.polygon = dotsPosNew # ->PoolVector2Array
currentPoly.antialiased = true
currentPoly.color = Color.aqua
add_child(current_poly)
– 1st test –
func _physics_process(delta):
if Input.is_action_just_released("ui_next_shape"):
var tween = get_tree().create_tween()
tween.tween_property(self.currentPoly,"polygon",newPoly.polygon,morphingSpeed) # newPoly.polygon : new PoolVector2Array
– 2nd test –
func _physics_process(delta):
if Input.is_action_just_released("ui_next_shape"):
for dot in currentPoly.polygon.size():
tween.tween_property(self.currentPoly,"polygon[dot]",newPoly.polygon[dot],morphingSpeed)
– “3rd test”
func _physics_process(delta):
if Input.is_action_just_released("ui_next_shape"):
for dot in currentPoly.polygon.size():
currentPoly.polygon[dot] = lerp(currentPoly.polygon[dot], newPoly.polygon[dot], morphingSpeed2)
So i’m wondering if polygon2D can be animated/tweened by code.
I’m completely stuck. If you have a solution, please let me know.
Thanks for your help.
P.S : Sorry, i don’t know why but all underscores and indents disappear when the text is published !