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

Welding Parts are Offset?

Asked by 8 years ago
Edited 8 years ago

I've been trying to make some constraint levers work for a few days now, they work fine and all except for the fact that the welding screws up and offsets the parts. (Screenshot below)

prntscr.com/dptvyp

Primary Weld Code

-- | Welds levers | --
Weld.WeldLever = function(Lever,CS,AS) -- Lever Model, Constraint Settings, Attachment Settings
    local Hinge = Constrain.Hinge(Lever,"Constraint",CS.LimitsEnabled,CS.UpperAngle,CS.LowerAngle,CS.Restitution,CS.ActuatorType,CS.AngularSpeed,CS.ServoMaxTorque,CS.TargetAngle)
    local A0 = Constrain.Attach(Lever.Joint0,Lever.Name.."Joint",AS.Position0,AS.Rotation0)
    local A1 = Constrain.Attach(Lever.Joint1,Lever.Name.."Joint",AS.Position1,AS.Rotation1)
    Hinge.Attachment0 = A0
    Hinge.Attachment1 = A1

    for i,p in next,(Lever:GetChildren()) do
        if (p.Name ~= "Joint0") and (p.Name ~= "Joint1") and (p:IsA("BasePart")) then
            Weld.NewWeld(Lever.Joint1,p,Lever.Joint1,p.Name.."Weld")
        end;
    end;

    for i,p in next,(Lever:GetChildren()) do
        if (p.Name ~= "Joint0") and (p:IsA("BasePart")) then
            p.Anchored = false
            p.CanCollide = false
        end;
    end;
end;

Weld Generator :

-- | Creates new Welds | --
Weld.NewWeld = function(p0,p1,Parent,Name)
    local w = Instance.new("Weld")
    w.Part0,w.Part1 = p0,p1
    w.C0 = p0.CFrame:inverse()
    w.C1 = p1.CFrame:inverse()
    w.Parent = Parent
    w.Name = Name
    return w
end;

Constraint Service :

Strain.Hinge = function(Parent,Name,LE,UA,LA,Rest,AT,Ang,Tor,TAMA) --Parent, Name (String), Limits Enabled (Boolean), Upper Angle (Int), Lower Angle (Int), Restitution (Int), Actuator Type (String[Servo,Motor or None]), Angular (Int[Angular Speed/Angular Velocity]), Max Torque (Int), Target Angle/Max Acceleration (Int) 
    local Hinge = Instance.new("HingeConstraint")
    Hinge.Parent = Parent
    Hinge.Name = Name
    if LE then
        Hinge.LimitsEnabled = true
        Hinge.UpperAngle = UA
        Hinge.LowerAngle = LA
        Hinge.Restitution = Rest
    end

    if AT == "Motor" then
        Hinge.ActuatorType = Enum.ActuatorType.Motor
        Hinge.AngularVelocity = Ang
        Hinge.MotorMaxTorque = Tor
        Hinge.MotorMaxAcceleration = TAMA
    elseif AT == "Servo" then
        Hinge.ActuatorType = Enum.ActuatorType.Servo
        Hinge.AngularSpeed = Ang
        Hinge.ServoMaxTorque = Tor
        Hinge.TargetAngle = TAMA
    else
        Hinge.ActuatorType = Enum.ActuatorType.None
    end
    return Hinge
end;

Help is greatly appreciated!

0
"Screenshot Below"? RubenKan 3615 — 8y
0
Forgot it lol, just posed it Lord_Hagenost 40 — 8y
0
Id suggest putting these 3 parts in a model, with an invisible part over it that is 2ce the length towards the center, so that you can use model:SetPrimaryPartCFrame() RubenKan 3615 — 8y
0
They're already in a model, I dont think you're understanding my code. This code sets up a lever model for constraint movement. Lord_Hagenost 40 — 8y
View all comments (5 more)
0
https://gyazo.com/b4a8eb2477f051de54b73de1a1f078e0 Something like this. Red part being the invisible part, green part being your lever-holder, black parts being the visible lever RubenKan 3615 — 8y
0
https://www.roblox.com/games/538077004/TARDIS-Gamma-REWRITE#!/game-instances, It would be easier for me to explain in game as to what my problem is. Lord_Hagenost 40 — 8y
0
No acces RubenKan 3615 — 8y
0
Making public. Lord_Hagenost 40 — 8y

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
8 years ago

--sending as discussed in game




local prev local parts = script.Parent:GetChildren() for i = 1,#parts do if (parts[i].className == "Part" or parts[i].className == "UnionOperation") then if (prev ~= nil)then local weld = Instance.new("Weld") weld.Part0 = prev weld.Part1 = parts[i] weld.C0 = prev.CFrame:inverse() weld.C1 = parts[i].CFrame:inverse() weld.Parent = prev end prev = parts[i] end end parts = script.Parent:GetChildren() for i=1,#parts do if (parts[i].className == "Part" or parts[i].className == "UnionOperation") then parts[i].Anchored = false end end wait() script:remove()
Ad

Answer this question