Godot Version
4.3
Question
Hello, I’m new to Godot and game programming in general.
I’m making a simple 2D game and I’m having a “bug” to animate a projectile from the game.
I have a Player that shoots a Projectile upwards. The projectile should move upwards for a few moment, then it should stop in Y position while the sprite is animated until its finished.
I have the following script on the projectile:
extends RigidBody2D
@export var lifespan = 0
var posY = 0
func _physics_process(delta):
linear_velocity.y = -4500 * delta
posY = global_position.y
await get_tree().create_timer(lifespan).timeout
linear_velocity.y = 0
global_position.y = posY
get_node("AnimatedSprite2D").play("falling")
await get_tree().create_timer(1).timeout
queue_free()
The problem is the behavior of the projectile its not consistent all the time, sometimes it stops at Y position, and other times it continues to move upwards a little bit.
Any ideas on how to fix the issue?
Thanks.