This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

The following used to work with V2.0 but no longer in V3.0:

apply_impulse(Vector2(), Vector2(0, -ACCELERATION).rotated(rotation))

It does the acceleration OK but the rotation seems to be locked straight up. I can no longer rotate and point where I want to go.

Here's the full code:

extends RigidBody2D

const ROTATE_SPEED = 250
const ACCELERATION = 5

func _physics_process(delta):
    if Input.is_action_pressed("ui_left"):
        rotate(-deg2rad(delta * ROTATE_SPEED))

    if Input.is_action_pressed("ui_right"):
        rotate(deg2rad(delta * ROTATE_SPEED))

    if Input.is_action_pressed("ui_up"):
        apply_impulse(Vector2(), Vector2(0, -ACCELERATION).rotated(rotation))

If I don't press UP, the LEFT and RIGHT will rotate the ship as expected. However, press UP and it locks going straight up, jiggling slightly if I press LEFT or RIGHT.

How do I make this work in V3.0?

in Engine by (260 points)

It looks as though apply_impulse is resetting rotation. I changed the code to this:

if Input.is_action_pressed("ui_up"):
    print("Ship rotation: " + str(rotation))
    apply_impulse(Vector2(), Vector2(0, ACCELERATION).rotated(rotation))
    print("Ship rotation: " + str(rotation))

I get this printout:

Ship rotation: -0.727221
Ship rotation: -0.727221
Ship rotation: 0
Ship rotation: 0
Ship rotation: 0
Ship rotation: 0
Ship rotation: 0
Ship rotation: 0
Ship rotation: 0
Ship rotation: 0
Ship rotation: 0
Ship rotation: 0
Ship rotation: 0
Ship rotation: 0

1 Answer

+1 vote

I think I've found a bug in V3.0

By storing the angle elsewhere and jamming it into roation, I get what I want:

func _physics_process(delta):
    if Input.is_action_pressed("ui_left"):
        angle -= delta * ROTATE_SPEED

    if Input.is_action_pressed("ui_right"):
        angle += delta * ROTATE_SPEED

    if Input.is_action_pressed("ui_up"):
        apply_impulse(Vector2(), Vector2(0, -ACCELERATION).rotated(deg2rad(angle)))

    // At this point rotation has been set to zero,
    // so set it to the angle I've computed
    rotation = deg2rad(angle)
by (260 points)

I've reported an issue on this: https://github.com/godotengine/godot/issues/15001

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 Frequently asked questions and 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 [email protected] with your username.