0 votes

I've made a kind of gate. Check a video: https://youtu.be/idbKdaFdkLM
I used RigidBody and set Custom Integrator true. Then I wrote this code:

extends RigidBody2D

func _integrate_forces(state):
    linear_velocity = Vector2(0, 0)
    pass

In the video you can see a console that outputs Y position of the object and position still changes. My method couldn't make it stop completely. If I directly change position, object doesn't revolve at all.

So can I freeze RigidBody on the place without making it Kinematic or Static, because it ruins the main feature of this object

in Engine by (12 points)

2 Answers

0 votes

I can't tell you why your approach doesn't work as expected (probably rounding errors in the rotation), but I can tell you there's a better way to do it - by using a PinJoint2D node:

https://kidscancode.org/godot_recipes/physics/joints_2d/

by (1,172 points)
0 votes

If you are talking about the Godot icon as a "gate", then the reason it isn't working is because it is rotating and thus has no linear_velocity.

But the best way to do this is this:

set_mode(RigidBody2D.MODE_STATIC)

When you want to stop it.

and then do:

set_mode(RigidBody2D.MODE_RIGID)

when you want it to move again.

by (93 points)
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