Move a RigidBody2D in the direction it's facing

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LikWid-Official

Hello, newbie here.

I’m trying to make a RigidBody2D Node apply a force in the direction it’s facing.

For example, if the object is facing upwards, I’d like it to apply a force to push it upwards, if it’s pointing right, apply a force to push it right, and so on. All I can seem to do is apply a force to push it in one constant direction, nothing more.

I’ve tried the apply_impulse function(s) with no luck to making this work; Just moves the RigidBody in a specific direction.
I’ve also tried using sin() and cos() functions with rotation_degrees with no luck.

Does anyone have any ideas/solutions?

For reference, I have a RigidBody2D with child nodes of a Sprite and CollisionShape2D. I made a small script to apply torque (and a failed attempt at force, hence why I’m here asking this question.)

 extends RigidBody2D

func _process(delta):
	if (Input.is_action_just_pressed("jump")) :
		apply_central_impulse(Vector2(0, -100))
	if (Input.is_action_pressed("left")) :
	if (Input.is_action_pressed("right")) :

Thank you in advance! (Sorry if this is a stupid question; I’m new to this engine)

:bust_in_silhouette: Reply From: ramazan

Look here