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

How to get relative rotation using BodyGyro?

I have a part that is pinning around the player, But I need to get a relative rotation at the same time, To create the effect that the part is always looking at the player, so the player only can see one face of the part.

I do have the CFrame of the player and part, but I can't not figure out how to use both of them to get the corrects Euler angles or the CFrame with the correct rotation to give to the BodyGyro.

Any help would be appreciated.

1 answer

✓ Accepted answer

There is a CFrame constructor that will do what you want. It takes in two arguments;

  • The origin of the CFrame

  • The lookPoint of the CFrame

You can use this constructor to make the BodyGyro look at the player. Just make the origin argument the Part's position, and make the lookPoint argument the player's position.

Example;

local plr = workspace.Goulstem --This is your player
local part = script.Parent --This is your part.

while wait(.1) do
	--This is the updated CFrame
	local looking = CFrame.new(part.Position,plr.Character.Torso.Position)
	part.BodyGyro.CFrame = looking;
end

Note: You may need to configure some of the other properties of your BodyGyro to produce the desired effect

1 comment

0

work good, thanks

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