0 votes

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")) :
        apply_torque_impulse(-100)
    if (Input.is_action_pressed("right")) :
        apply_torque_impulse(100)
    pass

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

Godot version 3.4.2
in Engine by (12 points)

1 Answer

0 votes
by (650 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.