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

How can I use a BodyGyro to make a bot face you?

Asked by 9 years ago

Normally I would just set the CFrame in a while loop.

while wait() do
    local direction = (plr.Character.Torso.Position - bot.Torso.Position) * Vector3.new(1, 0, 1)
    bot.Torso.CFrame = CFrame.new(bot.Torso.Position, bot.Torso.Position + direction)
end

But I want to decrease lag, so I started trying to use a body gyro.

local gyro = Instance.new("BodyGyro",bot.Torso)
gyro.D = 0
gyro.P = 9999
gyro.cframe = plr.Character.Torso.CFrame

Unfortunately it doesn't work at all -- the bot doesn't rotate. AutoRotate is disabled. Nothing is erroring in the output.

All variables are defined.

0
A math.abs ALMOST run's like a BodyGyro's cframe.. I would go to the wiki can look up math.abs MessorAdmin 598 — 9y
0
math.abs is just the absolute value. How will that help me? ZeptixBlade 215 — 9y
0
math.abs has the same value's as a BodyGyro CFrame. MessorAdmin 598 — 9y
0
math.abs(x) just returns the absolute value of x. Please explain how this can help me and how I can use it. ZeptixBlade 215 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

This is probably inefficient but it should work. If it does not work it is most likely due to welds or anchoring.

while wait(0) do
    gyro.cframe = CFrame.new(bot.Torso.Position,plr.Character.Torso.Position) - bot.Torso.Position
end
0
Unfortunately I wanted to get rid of while loops. Otherwise I would just use my first code block. ZeptixBlade 215 — 9y
Ad

Answer this question