Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added automatic block placement face detection #104

Merged
merged 7 commits into from
Jun 16, 2023

Conversation

GaspardCulis
Copy link
Contributor

My code is bad I advise editing it or even refusing PR, at least it compiles

@GaspardCulis GaspardCulis requested a review from adepierre May 22, 2023 07:27
Vector3<double> b_offset = neighbour_offsets[static_cast<int>(b)];
Vector3<double> a_to_player = a_offset - pos + Vector3<double>(0.5);
Vector3<double> b_to_player = b_offset - pos + Vector3<double>(0.5);
return player_orientation.dot(a_to_player) > player_orientation.dot(b_to_player); });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maths look sus. I need to make sure this indeed gives the face matching the player orientation

Vector3<double> b_to_player = b_offset - pos + Vector3<double>(0.5);
return player_orientation.dot(a_to_player) > player_orientation.dot(b_to_player); });
face = face_candidates.front();
return player_orientation.dot(a_offset) < player_orientation.dot(b_offset); // a < b because a negative dot product means the vectors are in opposite directions IE the player is looking at the face.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's working. Now it doesn't depend on the position of the block anymore, which means that it will return the same face for any block. The drawing below shows a case where it should return top face (i.e. bottom face of the neighbour) for A, but right face (i.e. left face of the neighbour block) for block B.

image

{
Vector3<double> a_offset = neighbour_offsets[static_cast<int>(a)];
Vector3<double> b_offset = neighbour_offsets[static_cast<int>(b)];
return player_orientation.dot(a_offset) > player_orientation.dot(b_offset);
Copy link
Owner

@adepierre adepierre Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that's seems good knowing the fact that the player is always looking at the block center. However, your previous commit had a < b and now a > b. Are you sure this one is the right one based on actual tests? Cause the face is also reversed regarding the current block (Down neighbour refers to the block ABOVE the current one, as you will place block on its down face). If you tested it that should be good to be merged!

@@ -79,11 +79,11 @@ namespace Botcraft
/// @param client The client performing the action
/// @param item_name The item to place
/// @param pos The location where we want to place the block
/// @param face The face on which the block is placed
/// @param face The face on which the block is placed. If not specified the optimal placing face will be automatically detected as the closest one to the player facing direction on a non-air block
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rephrase this to match more carefully the fact that the bot will look at the block.

Maybe "detected using the position of the block relative to the player eyes"

@adepierre adepierre merged commit cf3937b into adepierre:master Jun 16, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants