How to have a moving object affected by the gravity but not rotating the sprite

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Florix
:warning: Old Version Published before Godot 3 was released.

I would like to have a ball in my game that would be affected by the gravity, however i don’t want that the sprite rotate with the ball because i have a sort of shade effect on it. Thanks

:bust_in_silhouette: Reply From: Mohammad Hadi Aliakb

set the rigidbody to Character mode

can confirm this

ndee | 2016-02-24 06:10

:bust_in_silhouette: Reply From: Bojidar Marinov

If you want to allow the RigidBody2D to rotate, but want to keep the sprite upright at all costs, you can just rotate the sprite in the opposite direction. Sample script (assuming it is run on the RigidBody2D, and the sprite is a child of it):

var sprite
func _ready():
    sprite = get_node("Sprite")
    set_process(true)
func _process():
    sprite.set_rot(-get_rot())

Also, for a nicer effect, you can have one multiplicative Sprite for the shadow (which you keep upright), and another Sprite for the texture, that would rotate with the RigidBody2D. In this case the node tree would look like so:

ball (RigidBody2D)
-- shadow (Sprite) # You would use this one in the code above
-- texture (Sprite) # Leave this one to rotate