Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I change the angle of a constraint?

I used this script to make a mesh rotate around the axis of a brick (for the flap of a wing)

Here's a GIF: https://i.gyazo.com/2c8fa3af6f03c13d7be09670be5e72bf.gif

local a = script.Parent --Brick
local attachmentA = Instance.new("Attachment", a)
attachmentA.Position = Vector3.new(0, 0, -0.1)

local b = script.Parent.Parent["14"] --Wing flap
local attachmentB = Instance.new("Attachment", b)
attachmentB.Position = Vector3.new(1.053, 0.668, 1.473)
attachmentB.Rotation = Vector3.new(-18.33, 23.188, 7.432)

local hingeConstraint = Instance.new("HingeConstraint", a)
hingeConstraint.Attachment0 = attachmentA
hingeConstraint.Attachment1 = attachmentB

But I want to be able to control the angle of the flap. Is there any way to do this with constraints? Or shall I use something else to accomplish this? I'd prefer not to use CFrame due to its limitations with smooth movement.

1 answer

OK I figured it out, its just that the Wiki doesn't directly link to these pages so I had to find them on Google.

These pages helped: http://wiki.roblox.com/index.php?title=API:Class/HingeConstraint/ActuatorType http://wiki.roblox.com/index.php?title=API:Class/HingeConstraint/AngularSpeed

local a = script.Parent --Brick
local attachmentA = Instance.new("Attachment", a)
attachmentA.Position = Vector3.new(0, 0, -0.1)

local b = script.Parent.Parent["14"] --Wing flap
local attachmentB = Instance.new("Attachment", b)
attachmentB.Position = Vector3.new(1.053, 0.668, 1.473)
attachmentB.Rotation = Vector3.new(-18.33, 23.188, 7.432)

local hingeConstraint = Instance.new("HingeConstraint", a)
hingeConstraint.ActuatorType = "Servo"
hingeConstraint.AngularSpeed = 6.283 --6.28319 Radians per second equivalent to 1 revolution (full turn) per second
hingeConstraint.ServoMaxTorque = 1000000
hingeConstraint.TargetAngle = 20
hingeConstraint.Attachment0 = attachmentA
hingeConstraint.Attachment1 = attachmentB

This discussion is preserved as it was. New answers, comments, and votes are closed.