Having CFrame troubles

I normally have no issues with cframes, but for some reason I cant get this to work out.

I have a platform, when the character is on the platform, there is gravity.
If the player leaves the platform, there is no gravity, and the player floats.

The player is attached to the platform by a tether (a beam instance)

This works good, until I get to the limit of my tether (60 studs)

When the magnitude between the character and the start of the tether (its source) is > 60, I do the following.

I create a cframe.lookAt, with the source being tether start’s position.
Then I have it look towards the characters humanoid root part
So I should have a cframe positioned at the source of the tether, and facing the character.
Then I follow that cframe’s look vector, by adding 60 to it.
I then make this point the new end of the thether.

But something goes wrong.

Here is the code I am using

			if tether.SourceObject.Value then
				local srcCF = tether.SourceObject.Value.CFrame
				local dstCF = script.Parent.Parent.PrimaryPart.CFrame
				local length = (srcCF.Position-dstCF.Position).Magnitude
				
				if length > 60 then
					local cf = CFrame.lookAt(srcCF.Position,dstCF.Position)
					local pos = cf.LookVector*60
					dstCF = CFrame.new(pos)
					length = 60
				end
				
				tether.Attachment0.WorldCFrame = srcCF
				tether.Attachment1.WorldCFrame = dstCF 
			end

Thanks for any help

There are a couple things I can think of that that could be contributing. The first is that cf.LookVector is an arbitrary unit vector, so your character would be 60 studs from the origin in the same direction as what ever dstCF’s look vector is, so unless srcCF is at 0,0,0 you wouldn’t get expected results.

There are a couple solutions but the easiest would probably be to get the direction from src to dst (src → dst = dst - src), get that vector’s unit vector, then adjust the tether based on that (so something like tether.attachment1.WorldCFrame = srcCF + ((dstCF.Position - srcCF.Position).Unit * 60) should work)

Another possible reason this is happening is because attachments update based on their parents’ positions, not the other way around. So when you update the attachment’s WorldCFrame, it does get positioned properly, but your root will not move to where the attachment is.

PS. Is there a reason you can’t use rope constraints here? They might behave more predictably. You can toggle the visibility if you prefer the look of beams.

My bad, I forgot to add the original source position. So like you said, it was setting it to 60 studs from the origin.

The reason I wasnt using a rope constraint, was because I thought it was glitching.
I was using it, but every 2 out of 3 times testing, when I came back to the platform, I would ‘bounce’ between states of floating and not floating.

I couldnt get it to replicate the error when I removed the rope constraint.
So I decided to just use a beam.

However, just testing a few minutes ago, it did the same thing, the bouncing between states, so apparently it wasnt the rope constraint after all :stuck_out_tongue:

Thanks for the help though, at least that is one problem solved.

1 Like

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