Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't offsetting the CFrame... er... offset the CFrame?

I'm trying to offset this CFrame a little bit. I only really want an offset of a couple of studs, but that didn't do anything, so I changed it to 100. It still did absolutely nothing. Yes, my script is enabled and everything. There's no output. Idk why the cframe isn't being given an offset.

--The 'tor' variable is an NPC's Torso. I want the NPC to face you, with a slight offset.
local direction = (plr.Character.Torso.Position - tor.Position) * Vector3.new(1, 0, 1)
local offset = CFrame.new(0,0,-100) --A crazy big number, yet it still doesn't do anything?

BodyGyro.cframe = CFrame.new(tor.Position, tor.Position + direction)
BodyGyro.cframe = BodyGyro.cframe * offset

2 comments

1

Line 2, spelling mistake. You used tor.Position when it should read torso.Position.

0

Sorry about that, I changed the variable on line 5 so it would make more sense to people on this site, but my original variables are all 'tor' so unfortunately that doesn't solve it.

1 answer

BodyGyro only affects rotation, not position. If you want an offset, you should use a BodyPosition object as well as the BodyGyro (make sure to set the BodyForce.maxForce appropriately, depending on the mass of the object). Then, use the BodyPosition.position property:

BodyGyro.cframe = CFrame.new(tor.Position, tor.Position + direction)
BodyPosition.position = BodyGyro.cframe * offset.p -- offset.p instead of offset so that the result is a Vector3

This discussion is preserved as it was. New answers, comments, and votes are closed.