Hey! I am making a swinging ride system that uses HingeConstraints and motors. I am making it use Points (Parts) so when it hits that part it changes direction and keeps swinging back and forth at different height. This will make the cycle.
I have tried to make it so when it hits Point 1 it turns and variable to true so when it goes to Point 3 it does not hit Point 1 and change the Motor AngularVelocity back to Points 1 AngularVelocity.
Sorry if this does not make sense.
Code:
local hitPoint1 = false
local hitPoint2 = false
local hitPoint3 = false
local swingMotor = script.Parent.Motor.SwingMotor.MotorPart.HingeConstraint
local swingPoint1 = script.Parent.Motor.SwingMotor.Points.SensorPoint1
local swingPoint2 = script.Parent.Motor.SwingMotor.Points.SensorPoint2
local swingPoint3 = script.Parent.Motor.SwingMotor.Points.SensorPoint3
local function hitSensor1()
if hitPoint1 == false then
swingPoint1.Touched:Connect(function(hit)
if hit.Name == "SwingSensor" then
hitPoint1 = true
print("Hit sensor 1")
wait()
swingMotor.AngularVelocity = -12
end
end)
end
end
local function hitSensor2()
if hitPoint2 == false then
swingPoint2.Touched:Connect(function(hit)
if hit.Name == "SwingSensor" then
hitPoint2 = true
print("Hit sensor 2")
wait()
swingMotor.AngularVelocity = 20
end
end)
end
end
local function hitSensor3()
if hitPoint3 == false then
swingPoint2.Touched:Connect(function(hit)
if hit.Name == "SwingSensor" then
hitPoint3 = false
print("Hit sensor 3")
wait()
swingMotor.AngularVelocity = -35
end
end)
end
end
local function cycle()
print("Starting Swinging Ride Cycle!")
wait(1)
swingMotor.AngularVelocity = 7
hitSensor1()
hitSensor2()
hitSensor3()
end
wait(5)
cycle()
Thanks for any help.
Also they is prob a lot of ways to do this better but I am going to use this way for now.