Hello! I am working on a pantograph for trains and for the pantograph I would like it to raise or lower depending on the height of the overhead wire that is above the pantograph, so far I’ve kind of got it to work but the issue is it doesn’t raise properly.
I believe the thing that is causing this issue is the calculations I’m using but I’m not sure what to change or do. I’m horrible at math so yeah very hard for me to do but anyways…
Here is a couple screen shots of what is happening:
If the wire and the pantograph is the same on the Z axis it’ll raise properly but if not it’ll either be too low or too high.
How it should be:
It should always be touching the wire no matter what the Z axis difference is.
This pantograph is controlled by 3 motors. 1 motor controls the lower arm, 1 motor controls the upper arm and 1 motor controls the pantographs hand.
In the image below, each green dot represents a motor.
Top dot - Hand
Middle dot - Upper Arm
Bottom dot - Lower Arm
Here is the code that controls the lower arm and upper arm. The coding for the hand works perfectly so I have removed that from below.
local RaycastResult = workspace:Raycast(OriginRay.Position, OriginRay.CFrame.UpVector * 20, raycastParams)
if RaycastResult then
local Wire = RaycastResult.Instance
local Distance = RaycastResult.Distance
local LowerArmAngle = math.rad(-Distance * LowerArm.Size.Z)
local UpperArmAngle = math.rad(Distance * UpperArm.Size.Z)
LowerArm.Motor.C1 = CFrame.fromOrientation(LowerArmAngle / 2, 0, 0)
UpperArm.Motor.C1 = CFrame.fromOrientation(UpperArmAngle, 0, 0)
end
I’ve tried a million different ways to get it to try raise properly but nothing will work so I’ve now came here for help.
Thanks to anyone that can help!
This was a repost due to lack of activity in the last post.