Rope breaking works now

This commit is contained in:
Michal Pikulski
2025-09-21 23:37:02 +02:00
parent ef3b50b99f
commit 38f578c56a
2 changed files with 75 additions and 12 deletions

View File

@@ -107,7 +107,11 @@ public class RopeBreaker : MonoBehaviour
/// </summary>
private void CreateBreakPointTransform(Vector3 breakPointPosition)
{
// Create a new GameObject for the break point
// Store references to the original rope endpoints
Transform originalStartPoint = originalRope.StartPoint;
Transform originalEndPoint = originalRope.EndPoint;
// Create a new GameObject for the break point (attached to Player)
GameObject breakPointObj = new GameObject("RopeBreakPoint");
breakPointTransform = breakPointObj.transform;
breakPointTransform.position = breakPointPosition;
@@ -115,12 +119,15 @@ public class RopeBreaker : MonoBehaviour
// Add the physics follower component to the break point
RopeEndPhysicsFollower follower = breakPointObj.AddComponent<RopeEndPhysicsFollower>();
follower.targetTag = "Player";
// Set specific transform to follow instead of using tag
follower.SetTargetTransform(originalStartPoint);
follower.followSpeed = ropeFollowSpeed;
follower.trailing = ropeTrailing;
follower.useGravity = false; // Player rope end doesn't use gravity
follower.useGravity = true; // Player rope end doesn't use gravity
// Create second break point
// Create second break point (for the rock-attached end)
GameObject secondBreakObj = new GameObject("RopeBreakPoint_Second");
secondBreakTransform = secondBreakObj.transform;
secondBreakTransform.position = breakPointPosition;
@@ -128,7 +135,10 @@ public class RopeBreaker : MonoBehaviour
// Add physics behavior to second break point
RopeEndPhysicsFollower secondFollower = secondBreakObj.AddComponent<RopeEndPhysicsFollower>();
secondFollower.targetTag = "Rock";
// Set specific transform to follow instead of using tag
secondFollower.SetTargetTransform(originalEndPoint);
secondFollower.followSpeed = ropeFollowSpeed;
secondFollower.trailing = ropeTrailing;
secondFollower.useGravity = true; // Enable gravity for hanging rope end
@@ -139,7 +149,7 @@ public class RopeBreaker : MonoBehaviour
secondFollower.forceYReset = forceYReset;
// Create initial separation
Vector3 direction = (originalRope.EndPoint.position - breakPointPosition).normalized;
Vector3 direction = (originalEndPoint.position - breakPointPosition).normalized;
if (direction.magnitude < 0.01f) direction = Vector3.down;
breakPointTransform.position -= direction * initialSeparationDistance * 0.5f;