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

Body Objects question?

Asked by 10 years ago
bg = Instance.new("BodyGyro", c1:findFirstChild("Torso"))
bg.maxTorque = Vector3.new(math.huge, math.huge, math.huge)
bg.cframe = CFrame.new(char:findFirstChild("Torso").CFrame.lookVector)

So what I want the object to do is point in the direction my torso is facing, and everything is tagged properly, so what is the problem?

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

CFrame.new(Vector3) creates a CFrame at the position of Vector3 but in the default orientation. This is what you are using, so it just makes the part have the default orientation (front in -Z and top in +Y).

Instead, just use the CFrame of the Torso directly:

bg.cframe = char.Torso.CFrame;

You could also have constructed your own CFrame, but using the 2 argument CFrame.new constructor:

bg.cframe = CFrame.new( Vector3.new(), char.Torso.CFrame.lookVector );

(although this is not quite the same since this will not match the tipping of Torso, though will match the front direction)


Note that using FindFirstChild like this is just extra, unnecessary typing.

This is because this snippet will error if there isn't a Torso:(attempt to index a nil value for using .CFrame)

Use .Torso instead except in the actual condition that verifies there is a Torso.

Ad

Answer this question