Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 9 years ago

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
1
Line 2, spelling mistake. You used tor.Position when it should read torso.Position. aquathorn321 858 — 9y
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. ZeptixBlade 215 — 9y

1 answer

Log in to vote
0
Answered by
noliCAIKS 210 Moderation Voter
9 years ago

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
Ad

Answer this question