This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

How do I get position of a RigidBody that has mode 3 (Kinematic) set to it?

DetonatressDetonatress Posts: 43Member

Seems I can't get_pos of this, nor of the Area. I want to make the captured body move toward the center of Area.
I thought converting it to mode 3 would turn it into KinematicBody, but it's not being recognized as such, it's still RigidBody.

func _on_Area_body_entered(body):
    $Area.connect("body_entered", self, "_on_body_entered")

    if captured_crystal == null:
        captured_crystal = body
        body.custom_integrator = true
        body.mode = 3
        var direction = (body.get_pos() - $Area.get_pos()).normalized()
        body.set_pos(body.get_pos() + direction * 5)


  • DetonatressDetonatress Posts: 43Member
    edited June 2020

    I tried with updated "position()" instead of get_pos() too, and now it keeps telling me there is no position in base Area, but I have an area node called Area in the scene already.

    I tried with translation:

            var direction = (body.get_translation() - $Area.get_translation()).normalized()
            body.set_translation(body.get_translation() + direction * 2)

    Though I'm not sure how to instead make it smoothly head toward the center of the area (aka coordinate 0 of area) and stop there. I know I have to check if body.translation != keep doing the movement, but I do not know how to code the movement this way.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.