Trip Wire Sizing Issue

Hey all,

I’m trying to create a trip wire tool here, but the problem is when i finish clicking the second position the wire itself doesn’t align with the two points…

Code:

			
			local model = Instance.new("Model")
			model.Name = "TRIPWIRE_MODEL"
			model.Parent = workspace.TRIPWIRES
			
			local trip1clone = rs.TripWire1:Clone()
			local trip2clone = rs.TripWire2:Clone()
			trip1clone.Parent = model
			trip2clone.Parent = model
			
			trip1clone.Position = location1
			trip2clone.Position = location2
			
			local distance = (trip1clone.Attachment.WorldPosition - trip2clone.Attachment.WorldPosition).Magnitude
			
			trip1clone.Rope.Position = trip1clone.Attachment.WorldPosition
			trip1clone.Rope.Size = Vector3.new(distance, 0.1, 0.1)
			trip1clone.Rope.CFrame = CFrame.new(trip1clone.Attachment.WorldPosition, trip2clone.Attachment.WorldPosition) * CFrame.new(0, 0, -distance/2)
			

Any and all help would be fantastic, thanks in advanced!

This happens because of the part’s pivot point, cylinders front faces are usually the rounded sides so it points with that side instead of the bottom and top.

You can easily fix this by multiplying the cframe you have by 90 degrees:
* CFrame.new(0, math.pi / 2, 0)

There is also a more performant method by creating the directional vectors yourself and putting them in CFrame.fromMatrix but the fix I provided should be fine.

2 Likes

So doing what you suggested ended up with the same result.

			trip1clone.Rope.Position = trip1clone.Attachment.WorldPosition
			trip1clone.Rope.Size = Vector3.new(distance, 0.1, 0.1)
			trip1clone.Rope.CFrame = CFrame.new(trip1clone.Attachment.WorldPosition, trip2clone.Attachment.WorldPosition) * CFrame.new(0, math.pi / 2, 0)

image

I’m not too sure how it did seeing as the cframe is different?

It should be:

CFrame.new(trip1clone.Attachment.WorldPosition, trip2clone.Attachment.WorldPosition) * CFrame.new(0, 0, -distance/2) * CFrame.Angles(0, math.pi / 2, 0)

Sorry, typo, meant angles.

2 Likes

My apologies! I misunderstood haha, thank you so much this helped.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.