I’m working on implementing rod bending by blend tree.
Once, I’ve made a system to achieve that but then after I found out it doesn’t work correctly in every angles and situations.
I fills directionX
(First parameter of blend tree) and directionY
(Second parameter of blend tree) by using this code:
Vector3 projectedLineXY = Vector3.ProjectOnPlane(_baitHandler.transform.position - _context.rodTip.position, _context.rod.transform.forward);
float angleSignXY = Mathf.Sign(Vector3.Dot(Vector3.Cross(_context.rod.transform.up, projectedLineXY), _context.rod.transform.forward));
float angleXY = Vector3.Angle(_context.rod.transform.up, projectedLineXY) * angleSignXY;
Vector3 projectedLineZY = Vector3.ProjectOnPlane(_baitHandler.transform.position - _context.rodTip.position, _context.rod.transform.right);
float angleSignZY = Mathf.Sign(Vector3.Dot(Vector3.Cross(_context.rod.transform.up, projectedLineZY), -_context.rod.transform.right));
float angleZY = Vector3.Angle(_context.rod.transform.up, projectedLineZY) * angleSignZY;
_baitHandler.transform.position
is bait position and _context.rodTip.position
is tip of rod position. _context.rod
is rod gameObject and other things related to that are its directions.
Please if you know how I can achieve the correct solution for that, explain what exactly I can fill these 2 parameters of blend tree.