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

SPS: Enforce a minimum distance from plug to ring #166

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TheLastRar
Copy link
Contributor

Aims to reduce the undesired roll when the ring is too close to base of the penetrator.

One of the goals I had was to ensure that hypothetical hilted rings would behave correctly, while having a minimum distance smaller than the hilted distance.

With that in mind, I wanted to avoid a potential issue of a ring swinging under the minimum distance, and popping though.

DPS appears to consider a plane aligned to the base of the penetrator
I decided to take inspiration from this, and consider a plane with the same orientation as the orifice to impose a minimum distance against.

This approach is quite affective at reducing roll where the orifice is nearly aligned with the plug, but loses effectiveness as the orientation of the orifice approaches 90d.

The changes made in this contribution are free and unencumbered software
released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>```


// Consider plane aligned to orifice
const float orfPerpDistance = dot(sps_normalize(-frontNormal), rootPos);
float shiftLerp = (orfPerpDistance > minDistance) | (orfPerpDistance < -worldLength * hiltedSphereRadius) ? 0 : 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

ambiguous order of operations. Add parens and use || rather than | (although ultimately it probably results in the same machine code)

const float lerpDistance = minDistance;

// Consider plane aligned to orifice
const float orfPerpDistance = dot(sps_normalize(-frontNormal), rootPos);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this beneficial vs just using orfDistance directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was done for hypothetical hilted/uni-directional rings.

If we use orfDistance directly, we could end-up lerping out the min distance logic if the socket goes behind the plug, causing the plug to suddenly pull back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Including an sketch of the two
Drawing1 p1_cr

Where the dashed line shows the path of the plug as it moves pass/though the socket
I wanted to avoid the plug starting to lerp towards the original socket as it reaches the far end of the circled area.

float shiftLerp = (orfPerpDistance > minDistance) | (orfPerpDistance < -worldLength * hiltedSphereRadius) ? 0 : 1;

const float shiftAmount = (minDistance - orfPerpDistance);
const float3 shiftedRoot = rootPos - sps_normalize(frontNormal) * shiftAmount;
Copy link
Contributor

Choose a reason for hiding this comment

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

this arbitrarily just moves the socket backward, in respect to the direction it is facing, which I also don't think is correct in this scenario

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was based on your suggestion to "pretend" the rings are a bit forward.

Where you thinking of a different method when you suggested that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A Sketch showing what I'm attempting to achieve
Drawing2 p1_cr

shiftLerp *= sps_saturated_map(orfPlaneDistance, minDistance + lerpDistance, minDistance);

rootPos = lerp(rootPos, shiftedRoot, shiftLerp);
orfDistance = length(rootPos);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the ultimate goal? DPS's proximity solver is... not great, so I'm reluctant to take much inspiration from it at all. Much of DPS's logic feels very much like a "throw things at the wall and see what works", while I think we can do better by defining how the behavior should actually work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you referring to this section of code? or the whole PR in general?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ultimate goal was to avoid the sudden rotations in the plug under lateral movements as it gets close to the socket

Ideally I think this should be handled directly in the solver algorithm, however, I was unable to do so.

@TheLastRar
Copy link
Contributor Author

Returning to elaborate on my responses

I haven't really battle tested this as much as I wanted to, I ended up switching back to DPS full time I think due to hilted range being reduced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants