• 2D
  • Facing a Sprite into the direction of Node movement

Hi, I have a projectile (RigidBody2D) that shoots over the map and bounces off at the map border (StaticBody2D). The projectile also has a Sprite as child Node.

How can I point/rotate the Sprite into the direction the projectile is moving? I was not able to figure out the direction the projectile is moving. I was able to determine the collision point with the StaticBody2D and then use $Sprite.look_at(collision_point) but then the projectile faces backwards and I don't know how to invert the collision_point position so it will face the moving direction.

I am new to Godot but i think this may be what you are looking for

rotation = velocity.angle()

Good idea but RigidBody2D has no velocity property :(

@sfm said: Good idea but RigidBody2D has no velocity property :(

The property you are probably looking for is linear_velocity (documentation).

Also: Welcome to the forums :smile:

thank you both for your help, that worked

Cheered too soon :(

func _physics_process(delta):
	$RigidBody2D/Sprite.rotation = $RigidBody2D.linear_velocity.angle()

That's what i did. It works for the first few bounces. but soon the sprite isn't pointing at the correct direction anymore.

Here a Video of the problem:

And here what it looks like when it bounced for a few Minutes:

I am not sure if it is causing the issue or not, but one thing to try is to cancel out angular_velocity, so it does not rotate. Something like $RigidBody2D.angular_velocity = 0 should, I think, work.

Yes, I think it's getting double rotation (the rigid body is rotating as well as the sprite underneath).

I believe if you put this code on the rigid body 2d it will stop rotation.

func _integrate_forces(state):
    rotation_degree = 0

@cybereality said: I believe if you put this code on the rigid body 2d it will stop rotation.

func _integrate_forces(state):
    rotation_degree = 0

Looks like this has fixed it, will run a extended test tomorrow. Thank you all for your help.