In a 3D world, I’ve a hockey puck-like physique.
I’ve made a mechanic the place I can launch the puck with a slingshot mechanism.
However the level of contact is set with a raycast and the “sling draw” will be in any arbitrary (XZ aircraft locked for simplicity) course.
Seen within the picture:
- BLUE circle = puck
- BLACK circles = factors of contact (pressure factors) will be wherever on the sting
- RED line = pressure vector of 1 potential draw, that’s straight aligned with heart, therefore shouldn’t be deflected (in sport this precision wouldn’t be attainable, so there would at all times be some deflection)
- GREEN line = pressure vector of one other potential draw, that’s off heart, that must be deflected
- BLUE dashed line = regular from heart of mass
At the moment I am attempting to compute it utilizing:
// Can draw max as much as 2 items
var springMaxDistance = 2f;
// Power utilized per items drawn
var springStrength = 5f;
var springVector = forcePoint - drawPoint;
// Decide the vector from pressure level to mass
var massVector = forcePoint - centerOfMass;
// Derive how a lot of massVector is parallel to springVector
var massParallelVector = Vector3.Undertaking(massVector, springVector);
// Derive the rest as perpendicularity
var massPerpendicularVector = massVector - massParallelVector;
// Restrict the utmost spring distance
var springDistance = Mathf.Min(springVector.magnitude, springMaxDistance); // Prevents winding greater than allowed
// Compute the pressure that must be utilized
var springForce = springStrength * springDistance;
// Derive how a lot of most pressure is to be utilized
var forceRatio = springForce / (springStrength * springMaxDistance);
// In addition to how offset (perpendicular) the shot is from it is heart
var offsetRatio = massPerpendicularVector.magnitude / massVector.magnitude;
// Decide how a lot to deflect
var deflectionMagnitude = offsetRatio * forceRatio;
// Generate the deflection vector primarily based (for 0 perpendicularity, this is able to be nothing - straight shot)
var deflectionVector = massPerpendicularVector.normalized * deflectionMagnitude;
// Combine
var launchVector = (forceVector - deflectionVector).normalized * springForce;
And, to additionally add any torques crucial, I am making use of the pressure as such:
rigibody.AddForceAtPosition(launchVector, startPoint, ForceMode.Impulse);
It really works as anticipated for straight photographs, like:
But I do not really feel like that is bodily correct although. For some angles, this produces bizarre vectors – like:
IDK if for such an excessive angle, the produced launchVector is smart. I really feel it must be sharper.
I’ve been googling for hours and can’t discover the appropriate key phrases to seek out the correct physics formulation for this.
I cobbled this method up with LLM.