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.
#Drawing a circle at the position of a RigidBody2D node
1 messages · Page 1 of 1 (latest)
custom drawing should already be relative to the RigidBody as long as you're doing it inside its draw function.
Godot Engine documentation
Introduction: Godot has nodes to draw sprites, polygons, particles, text, and many other common game development needs. However, if you need something specific not covered with the standard nodes y...
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).
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
OK, there you go.
position isn't needed. it's already drawn relative to the node, kinda like a child.
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.
Ah, that makes sense. So, I just pass a Vector2.Zero to the DrawCircle call, I guess.
yeah
not sure what you mean by that
It's Australian slang expression meaning something along the lines of "homemade crap is normally a pretty dodgy, but this one works like a good commercial product." 🙂