Skip to content

Facing Relative Vector Offset #7925

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev/feature
Choose a base branch
from

Conversation

erenkarakal
Copy link
Member

@erenkarakal erenkarakal commented Jun 6, 2025

Problem

There isn't a shorthand way to offset a location while considering rotation.

Solution

Adds a new pattern to the existing offset syntax. This can be compared to ^^^ in vanilla commands (like /summon tnt ^1 ^2 ^3)

before:

set {_v} to vector from yaw player's yaw, pitch player's pitch
set vector length of {_v} to 3
spawn tnt at player ~~ {_v}

with this PR:

set {_l} to player's location offset by vector(0, 0, 3) using local axes
spawn tnt at {_l}

and this isn't even showing the work you would've done to achieve an X or Y offset at the same time

I was going to update the syntax description but not sure how I should explain this

Testing Completed

Only manual testing was done, comparing the syntax to the vanilla Minecraft command


Completes: none
Related: none

@erenkarakal erenkarakal requested a review from a team as a code owner June 6, 2025 18:25
@erenkarakal erenkarakal requested review from Burbulinis and TheMug06 and removed request for a team June 6, 2025 18:25
@erenkarakal erenkarakal changed the title Feature/facing relative vector offset Facing Relative Vector Offset Jun 6, 2025
Comment on lines +96 to +99
Vector o = new Vector(0, 0, 0);
o.add(left.multiply(offset.getX()));
o.add(up.multiply(offset.getY()));
o.add(forward.multiply(offset.getZ()));
Copy link
Member

Choose a reason for hiding this comment

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

Why not initialize the XYZ values directly?

*/
private static Location getFacingRelativeOffset(Location loc, Vector offset) {
Vector forward = loc.getDirection();
Vector up = new Vector(0, 1, 0);
Copy link
Member

Choose a reason for hiding this comment

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

this isn't actually the local up direction

Copy link
Member

@sovdeeth sovdeeth Jun 6, 2025

Choose a reason for hiding this comment

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

You may want to replace this whole method with Quaternionf.rotationZYX and use that to transform the vectors

@sovdeeth sovdeeth added the feature Pull request adding a new feature. label Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Pull request adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants