#Drawing a circle at the position of a RigidBody2D node

1 messages · Page 1 of 1 (latest)

severe lark
#

I have a RigidBody1D node I want to represent on screen as a simple dot. (In C#) I'm using a DrawCircle() call in the RigidBody's script to draw he circle. If the RigidBody's Position is {0,0}, then the drawn circle and the RigidBody's collision area are concentric, but if I move the Position to, say, {100,100} the collider area and the drawn circle no longer coincide, with the circle being drawn twice as far from the origin as the collider. So I'm presuming that I need to apply a transform to the node's Position before passing it to the DrawCircle() call. The problem is that I'm clueless as to what transform I need to apply 🙂 Any suggestions are welcome.

long idol
#

with all you've wirtten it's hard to grasp what exactly the situation is. so mind sharing some screenshots and code?

#

it being twice the distance sounds to me like you're constantly updating the draw-function with the current position/transform of the rigid body. But as i stated you don't have to do that, as what you draw will already be relative to the node, so just keep it at (0,0).

severe lark
#

Here's the only script in the test scene...

using Godot;

public partial class DotTest : RigidBody2D
{
    [Export] private float _radius = 16.0f;
    [Export] private Color _colour = Colors.Red;

    void _draw()
    {
        GD.Print($"_draw() at:{Position}");

        Vector2 drawPosition = Position;
        DrawCircle(drawPosition, _radius, _colour, true);
    }
}
#

And 3 shots of the running scene with the DotTest node having Positions of {0,0}, {50.50}, and {200,200}

#

And finally, the tree of the scene I'm running

long idol
#

because just so you know: the draw function only gets called once by default and the parameters of the methods get cached. so for it to follow the rigid body in any way its position being relative to it is already required.

severe lark
severe lark
#

Awesome. Thanks mate.

#

Just to confirm, it now works like a bought one.

long idol
severe lark