i have a vector3 value that updates perfectly fine, and i have two motor6Ds (vertical and horizontal) and i want them to position so it faces towards the desired vector3. i am unfortunately unable to do this as i am awful at scripting. any help would be massively useful.
(the image in question is from when it was a pair of hinge servos, but it’s basically the same setup)
Can you explain in more details what you want?
if i put the desired position to 40 studs left and 30 studs up from the gun’s origin point i would want it to rotate both constraints so the horizontal one is rotated to look at the 40 studs left position and the vertical one is rotated to look at the 30 studs up position
Well first, you need to use CFrame.LookAt() which basically returns the orientation of a position looking at another position, then convert that CFrame to radians. Then you’ll be able to rotate the constraints to the specified orientations. You probably don’t understand but that’s fine, here’s the code, if you wanted it in code, I’m honestly not sure if you did.
local YourModel:Model = workspace.Gun.WorldPosition -- I'm assuming you have a model of the gun, and not a part
local Pos1 = Vector3.new(--Desired Position)
local LookAt = CFrame.lookAt(YourModel.Position,Pos1) -- Creates a new CFrame
local radX, radY, radZ = LookAt:ToOrientation() -- Gets the orientation in radians
YourModel.HingeLeft.Radius = radX
YourModel.HingeUp.Radius = radY
This may or may not work, I don’t have your game to try it so good luck : P
will try this later. hopefully it actually works and saves me weeks of frustration.
i don’t think this is going to work since i’m using them in servo mode and the fact that it needs a targetangle in degrees and not a radius in radians
You can convert the radians to degrees like this
local radX, radY, radZ = LookAt:ToOrientation()
local newOrientation = Vector3.new(math.deg(radX),math.deg(radY),math.deg(radZ))
print(newOrientation.Y) -- prints the y orientation
Mind showing me how you’re applying the script?
switched to a pair of motor6Ds, for the sake of my sanity. still need help with this.
I can’t really help you if I don’t know what’s going on :d
i have a position (given as a vector3) that i want the motor6Ds to rotate so it faces it. think of it like a tank turret where the barrel and the body of the turret rotate on 1 axis each.
The Script I used
local TestFolder = script.Parent
local Pos1 = TestFolder.LookAt.Position
local TweenService = game:GetService("TweenService")
local info1 = TweenInfo.new(0.7)
local LookAt = CFrame.lookAt(TestFolder.Anchor.Position,Pos1)
local radX, radY, radZ = LookAt:ToOrientation()
for i=1, 3 do
print("waiting")
task.wait(1)
end
TweenService:Create(TestFolder.Anchor.RotatorSide,info1,{Transform = CFrame.new(0,0,0)*CFrame.Angles(0,radY,0)}):Play()
--TestFolder.Anchor.RotatorSide.Transform = CFrame.new(0,0,0)*CFrame.Angles(0,radY,0) -- moves ir with no Anim
task.wait(1)
local LookAt2 = CFrame.lookAt(TestFolder.RotatorUp.Position,Pos1)
local radX, radY, radZ = LookAt2:ToOrientation()
TweenService:Create(TestFolder.RotatorSide.RotatorUp,info1,{Transform = CFrame.new(0,0,0)*CFrame.Angles(radX,0,0)}):Play()
--TestFolder.RotatorSide.RotatorUp.Transform = CFrame.new(0,0,0)*CFrame.Angles(radX,0,0) -- moves ir with no Anim
As you can see, it works. However, I know damn well the model isn’t made like yours, so to make it easier on me when you ask for help implementing this into your model, SHOW ME YOUR SCRIPT AND MODEL.
one TINY issue with this: i need the base to be unanchored and as far as i remember tweens don’t work on unanchored stuff