Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | OverBern | |
Old Version | Published before Godot 3 was released. |
I want to implement stretching in an abstract 2d top-down shooter. So when a character or projectile is moving fast, it becomes longer in that direction. Currently my best attempt is this:
func _fixed process(delta):
#rotate the node2d so y matches the direction the RigidBody2D is going
set_global_rot(Vector2(0,1).angle_to(.get_parent().get_linear_velocity()))
#make it longer in that direction by increasing y based on the RigidBody2D's speed
set_scale(Vector2(1, 1+((get_parent().get_linear_velocity().length())/AL.maxSpeed)*0.618034))
This script belongs to a Node2D with nodes for the visuals i want to stretch inside. This node’s parent is a RigidBody2D.
This method means the visuals rotate with the node2D, rather than just stretching - if the character is moving and aiming forwards, then starts running backwards, its face and chest will suddenly be facing backwards. I can probably just rotate them back constantly, but I feel like there has to be a more elegant way of changing scale in directions other than the local x, y and z. I wish to be told such a way.