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

Code needs to be repeated 2 times to work fully (property not updated fast enough)?

Asked by 4 years ago
Edited 4 years ago

Please help i dont want to have bad code!

So basically i want the part to turn toward's the camera, It does but the orientation isn't changed at all, For it to be fixed i have to execute this 2 time's and i know that's a bad practice!

My guess is the code isn't updating the part's property's fast enough so the part where it says "m.Orientation.Y" isn't updated, I was thinking to put a wait() but i know that's a bad practice i tried to make this super simple sorry if it's still hard to read.

local m = workspace.monitor
for i = 1,2 do
--Make part look at camera
m.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position,m.Position)
--Make part go 2 studs in front of camera
m.Position = workspace.CurrentCamera.CFrame.Position + workspace.CurrentCamera.CFrame.LookVector * 2
-- Make the part keep it's Y coordinate so it isn't changed idk why it changes help?
m.Position = Vector3.new(m.Position.X,9.87,m.Position.Z)
--This is the part where it needs to be executed twice my guess is the code is going too fast?
m.Orientation = Vector3.new(-90,m.Orientation.Y ,m.Orientation.Z)
end
0
If you want to make is faster, use RunService Ziffixture 6913 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago
Edited by DeceptiveCaster 4 years ago

So I see that you set the 'monitor's CFrame. Well, CFrame.new() takes quite a few parameters, but what you should be worried about is the first 2. CFrame.new(position, lookVector);

If you wanted a part to face, for example, Baseplate, but have it stay in it's position, you would do

part.CFrame = CFrame.new(part.Position, workspaxe.Baseplate.Position);

Notice how both parameters are Vector3s.

You can furthermore add onto this by multiplying CFrames for rotation or movement (i.e. CFrame.Angles()).

For example, if you wanted to rotate something on the Y-Axis by 90 degrees, you would do:

part.CFrame = part.CFrame * CFrame.Angles(0, math.pi/2, 0);

Keep in mind that CFrame.Angles() only accepts radians. You can convert a degree to radians by using math.rad(degree).

Here are some resources that can help you get started with CFrame math.

CFrame Math Operations

Understanding basic CFrame concepts

What are CFrames? (Includes CFrame.Angles())

0
Converted the provided links into hyperlinks to save the hassle of having to copy and paste the links. DeceptiveCaster 3761 — 4y
Ad

Answer this question