-
Notifications
You must be signed in to change notification settings - Fork 45
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
Added automatic block placement face detection #104
Conversation
Fix typo
…sets and code consistency This should fix all issues in my PR
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); }); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
{ | ||
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"
My code is bad I advise editing it or even refusing PR, at least it compiles