This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm making a very basic Billiards game as my first Godot project. I've managed to create a basic play area of "table", "pockets", and "cushions" and the various balls all bounce around as expected.

The issue I'm facing is when I try to design some functionality around the "pocketing" of the balls.
i.e. when a Ball collides with a Pocket, it should momentarily disappear from the screen. Then, once all of the balls have stopped moving, any pocketed balls should be replaced on their starting position.

The way that I've coded it up does not work, however, because the Ball appears to be re-positioned (for what seems to be a single frame) to the correct spot, it instantly hops back to the Pocket in which is had been "sunk".

I believe this is probably related to the ordering of physics events, and I need to defer setting the Position property until after all the "physics" has happened but I feel like I may be going about this the wrong way to begin with.

Any help would be much appreciated.

enter image description here

Godot version v3.5.1
in Engine by (12 points)

1 Answer

0 votes

Add this function in your RigidBody2D script:

func move_to(location):
    position = location

You can call it whenever you need to set the RigidBody2D's position:

by (733 points)

Thanks for the suggestion, unfortunately this has not solved the problem.
I converted your suggestion to the C# equivalent (below) but I still see the same results: The ball is moved back to the correct position for what seems like one frame of animation, and then is immediately moved back to a location on top of the "pocket".

internal void Reset()
    GD.Print($"Setting {this} Position to {StartPosition}");
    Mode = ModeEnum.Static;
    Position = StartPosition;
    Mode = ModeEnum.Rigid;
    //SetDeferred("position", StartPosition);
    GD.Print($"{this} Position: {Position}");
    Visible = true;
    IsPocketed = false;
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 Frequently asked questions and 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 [email protected] with your username.