Skip to content
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

Method to get relative object position (attachments) #14696

Open
GreenXenith opened this issue May 24, 2024 · 3 comments
Open

Method to get relative object position (attachments) #14696

GreenXenith opened this issue May 24, 2024 · 3 comments
Labels
Feature request Issues that request the addition or enhancement of a feature @ Script API

Comments

@GreenXenith
Copy link
Member

GreenXenith commented May 24, 2024

Attached entities are considered by the server to be at the parent origin. However, the server knows the position and rotation of attachments and parents (aside from armature stuff), so it should be able to solve for child positions/rotation.

The solved relative position should be used for both an object method and raycasting (see #10304).

object:get_pos() could natively return this relative position, though that could break some mods. Alternatively a new flag like object:get_pos(relative), or a new method like object:get_relative_pos().

@GreenXenith GreenXenith added the Feature request Issues that request the addition or enhancement of a feature label May 24, 2024
@FatalError42O
Copy link

object:get_attach()? that will tell you the position given in :set_attach(). Maybe I misunderstood the issue, but we already can get the relative position of an object.

It kind of sounds like you want the global position of an attached object? I'm not sure. But either way this is something that can be entirely implemented in lua with existing tools

@FatalError42O
Copy link

FatalError42O commented Jun 17, 2024

if you mean the position of the object in the global system relative to the object (so attached_pos-parent_pos) then you can just make a rotation matrix from the parent's rotation and multiply that by a 3x1 vector, then subtract the object position. https://www.symbolab.com/solver/matrix-multiply-calculator may help

@appgurueu
Copy link
Contributor

appgurueu commented Jun 17, 2024

Yes, this can be implemented in Lua. Since there is no library doing this yet, modders are presently usually just using the incorrect get_pos however. A pure Lua implementation also can't really attain the same performance.

The engine should provide this, especially since it needs this itself (if we are to make a better effort for raycasts). Related: #14231 contains code to calculate transformations along the attachment chain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request Issues that request the addition or enhancement of a feature @ Script API
Projects
None yet
Development

No branches or pull requests

4 participants