Daw588
(Daw588)
March 15, 2022, 9:28pm
#1
Hello, I am trying to make Motor6D
joint look at Part
's position which is Vector3
.
Simple rotation such as the one below works like a charm.
turretMotor.C0 *= CFrame.Angles(0, math.rad(90), 0)
However, I need to make it look at a Vector3
position. So I tried the following:
local target = script.Parent.Target
local motor = script.Parent.Tank.Base.Motor
local turretCF = motor.C0
while true do
-- Dont crash Roblox
task.wait()
-- C0 is in a object space so we should convert target position to object space as well?
local targetCF = target.CFrame:ToObjectSpace(turretCF)
motor.C0 = CFrame.lookAt(turretCF.Position, targetCF.Position) -- Update the C0
end
Structure
Video
As you can see it doesn’t work. I would like to know why it doesn’t work and how to fix the issue. Thanks!
Bikereh
(green_lady)
March 15, 2022, 9:33pm
#2
if the turret will stay there and not be moved then you can just anchor it and remove the motor6d. then you can do this:
motor = CFrame.new(turretCF.Position, targetCF.Position)
1 Like
Daw588
(Daw588)
March 15, 2022, 9:34pm
#3
I understand, I know that, however, I am using Motor6D since I want it to work with moving assembly.
Bikereh
(green_lady)
March 15, 2022, 9:36pm
#4
do you mean that their going to move around?
Bikereh
(green_lady)
March 15, 2022, 9:39pm
#5
what is part1 and part0 of the motor6d
Bikereh
(green_lady)
March 15, 2022, 9:45pm
#7
this should work
local target = script.Parent.Target
local motor = script.Parent.Tank.Base.Motor
local turretCF = motor.C0
local turret = script.Parent.Tank.Turret
while true do
-- Dont crash Roblox
task.wait()
-- C0 is in a object space so we should convert target position to object space as well?
motor.Part1 = nil
turret.CFrame = CFrame.new(turret.Position, target.Position)
motor.Part1 = turret
end
1 Like
Daw588
(Daw588)
March 15, 2022, 9:48pm
#8
Now it does nothing, regardless of where I move the “target” part.
Bikereh
(green_lady)
March 15, 2022, 9:49pm
#9
are there any errors? is the game even running?
Daw588
(Daw588)
March 15, 2022, 9:50pm
#10
There are no errors, and the game is indeed running.
Bikereh
(green_lady)
March 15, 2022, 9:50pm
#11
try chinging this:
motor.Part1 = nil
turret.CFrame = CFrame.new(turret.Position, target.Position)
motor.Part1 = turret
to this:
motor.Part0 = nil
turret.CFrame = CFrame.new(turret.Position, target.Position)
motor.Part0 = motor.Parent
Daw588
(Daw588)
March 15, 2022, 9:52pm
#12
Now the turret is detached from the base. I don’t think that messing with Part0 and Part1 properties you will achieve anything not “hacky”.
Bikereh
(green_lady)
March 15, 2022, 9:52pm
#13
yeah i guess your right lemme try finding soemthing else
Daw588
(Daw588)
March 15, 2022, 9:53pm
#14
Here my other attempts:
local function lookAt(base: CFrame, target: CFrame)
return (base - base.Position):Inverse() * CFrame.new(Vector3.zero) * CFrame.Angles(math.pi / 2, 0, 0)
end
local function lookAt2(root: Part, origin: CFrame, target: CFrame)
local direction = (Vector3.new(target.Position.X, origin.Position.Y, target.Position.Z) - origin.Position).Unit
return CFrame.Angles(3 * math.pi/2, 0, math.pi) * CFrame.Angles(0, 0, -math.asin(direction.X)) * CFrame.Angles(0, 0, math.rad(-root.Orientation.Y)) * CFrame.Angles(-math.asin(direction.Y), 0, 0)
end
Both didn’t work.
I got them from here:
This is what I worked out so far
local he = true while he==true do wait() local x,y,z = CFrame.new(workspace.Dummy.Torso["Right Shoulder"].C0.Position,workspace.ar.Position):ToOrientation() workspace.Dummy.Torso["Right Shoulder"].C1=workspace.Dummy.Torso["Left Shoulder"].C1*CFrame.fromEulerAnglesXYZ(x,y,z) print(tostring(x)..", "..tostring(y)..", "..tostring(z)) end
But it’s not right
Solution found in this tweet.
Bikereh
(green_lady)
March 15, 2022, 10:04pm
#15
i think i found something that works
Hello there, it’s me again with a small resource that I see lacking on the forum with many ,unsolved , or ones that have the general idea but incomplete scripting support questions.
Credits
@sleitnick , PID Controller from AeroGameFramework, works great but semi modified to accommodate Vector3 variables.
@ThanksRoBama , Great tutorial on PID Controllers which had excellent yet simple explanation along with great examples. Never knew it was possible to just work with P alone.
Summary
What …
1 Like