0 votes

I'm trying to make something like a rocket, with two thrusters. Ship is RigidBody2D, thrusterPoints are simple Nodes2D that are placed on the sides. I'm trying to "drive" the rocket, just by adding force to one thruster or the other.

I have script attached to the RigidBody2D

onready var forcePointLeft = $ForcePointLeft

func _integrate_forces(state: Physics2DDirectBodyState) -> void:
  add_force(forcePointLeft.position, (Vector2.UP * 10).rotated(rotation))

(I added some gravity and stuff, to make it not just fly off into space, but with zero gravity it works the same)
In this case, I expect the rocket to spin in single direction, as it has constant force beeing added to it all the time. It doesn't behave as expected -.- It does something weird, like on gif below.
weirdly spinning thing

Why is that happening? how is that possible?

in Engine by (12 points)

That will happen if you constantly call add_force every frame and the code you've provided will cause it to spin continually. You need to set conditions and call apply_impulse for a single frame.

That's okay, I expect it to spin continuously, for this code example. but as you see on gif - it does not spin continuously - you can see that on first 'loop' it goes around half-way, and then goes back - that is not logically possible, without providing additional force the other way around.

Even if I try doing it like this:

  if(Input.is_action_just_pressed('ui_left')):
    apply_impulse(forcePointLeft.position, ((Vector2.UP) * 100).rotated(rotation))

And then I mash the button repeatedly, it goes like this:

enter image description here

That maybe because you're using local coordinates, try

apply_impulse(forcePointLeft.global_position, global_transform.xform(Vector2.UP) * 100))

Nope, that's also not global/local position.

Finally I have found the reason for the problem:

apply_impulse(forcePointLeft.position.rotated(rotation), ((Vector2.UP) * 40).rotated(rotation))

For some weird reason, force point has to be rotated, even though it's node inside the ship structure.

Please log in or register to answer this question.

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.

Categories