Pantograph raising and lowering system

Hello! I am wanting to get a parts Y axis but from another parts X axis.

Basically I want to make the parts position be at the same position as the wire but the X axis being somewhere else along the wire and the Y axis being the same as image 2. If the cubes X axis was the lower point of the wire then the Y axis of the cube would be centered. Sorry for the bad explanation.

I assume its got something to do with CFrames and math but I’m not really good with CFrames or math. I’ve tried using chat GBT for help but that doesn’t really work because it doesn’t really understand me and it can’t read images.

Image 1:

Image 2:

Thanks to anyone that can help.

4 Likes

Hi, its been a couple hours and I’m really needing a solution to this.

If anyone would like me to add more things or explain some more please let me know.

Thanks!

2 Likes

Yeah, I dont understand exactly whats your goal.
What I understand is, that you want by scripting place a box along the wire.

Im not good at math either… but I think its easy.
For example, set the box CFrame to the same CFrame of the wire, then use the LookVector or any Vector to extend the CFrame coordinate of the Box along the wire, for example the half of the wire size, or certain studs

2 Likes

Ok lets try this.

I’m working on a pantograph for a train but wanting it so the pantographs hand (the top part) touches the wire and the way it works is it gets the Y axis of the wire so when its raised it’ll only raise to the very center height of the wire and not the height that’s above the pantograph. This works good when the wire is level because all the height is the same but when the wire is rotated then it think that the wire is all the same height when its not.

Do you understand what I’m trying to do a bit better?

As you can see its only raised to the center of the wire not the correct spot

1 Like

I think I get it now. I just learned what a pantograph is too… LOL

Ok, so that thing rises, and ofc you want it to stop when it touch the cable. That thing in trains I suppose is for electricity? well offtopic.

For a task like that maybe trying to use Raycasting could work, you cast a ray from the hand of the pantothing and get the exact coordinates where it hits the wire, so you get the exact coordinates where hand should rise.

2 Likes

Lol yes its for the electricity. I don’t really like using raycasts. I’ve figured out how to position that cube from the main post with look vector but i’m trying to figure out how to get the Y position and to make the X axis the same as the hand.

1 Like

I dont get it, the idea of using the LookVector is for you dont need to get the Y coordinate, look this video:

You can use the CFrame look vector approach, but, you would need to find how far is the pantothing from the middle of the wire on X axis, so you can easily define by how much to multiply the look vector


Why you dont like Raycasting if its one of the most common features used in games?
Now ShapeCasting exist, so you can fire a wide shape to find the wire instead of casting multiple rays for it.

1 Like

I’m needing to get the Y axis because the code I use to raise the pantograph gets the Y axis to get how high it is.

I kind of think its just a waste for features that could work with 1 line instead of multi.

1 Like

Then change the code. As you can see in the video I sent I dont need the Y axis, the Y axis is created automatically when I offset the Box along the wire. You just need the X coordinate on how far is the panto from the center of the wire part.

The box is perfectly placed on the wire Y axis, cause Im not needing only the Y axis. Im creating a whole new CFrame coordinate, so I can tell the hand to place it in the right place…

And you could simply extract the Y coordinate from the new CFrame so easily if you only need the Y coordinate…

No, its not, and that could solve your issue very quickly.

1 Like

The videos not really loading properly because my Wifi is bad… lol.

I just need the Y number and that’s it, I don’t need to adjust the position of the CFrame, the way the pantograph goes up and down is with hinge constraints but I’ve already that part sorted it just uses the Y axis to find the angle the arms should be but the Y axis it gets right now is the wire Y axis not the Y axis above the pantograph hand.

Also I don’t exactly know how to use raycasts, lol.

I’ve also managed to get the Y axis, just not very centered…

image

1 Like

I think you’ve confused yourself. You don’t get y from x, you get y from y. So the y axis (in the world position) of the wire between point_A(Wire start) and point_B(Wire end) “I’m assuming is a straight line”. So you would just get the Y axis from a small invisible part or a point attached to the train’s arm and the wire. Raycasting is the way to go here as the other people have stated.

1 Like

Sad you cant watch the video, Im showing how with only one line of code Im placing the hand in the right place of the wire on multiple angles of the wire. Im changing constantly the angle of the wire and the hand always gets the perfect position.

By building a new CFrame based on the wire I just offset a distance for the box. Very simple.

But that would require for you to know where is the train placed based on the X coordinate of the center of the Wire.

1 Like

Some pics, cause you cant watch the vid:

This works

local Distance = Wire.Position.X - Hand.Position.X

local Y = (workspace.Wire.CFrame + -workspace.Wire.CFrame.RightVector * Distance).Y

And when the train and wire is rotated? you are only checking X what if the looking vector is on Z?

Wait what should I be doing then when the train is rotated and the wire is rotated?

Im testing too, its not like I know the answer haha, I would prefer to do this with Raycasting. This is working fine for me even when its rotated:

local box = workspace.Box
local wire = workspace.Wire
local offset = (box.Position + Vector3.new(0, wire.Position.Y - box.Position.Y, 0) - wire.Position).Magnitude

box.CFrame = wire.CFrame + (wire.CFrame.LookVector * offset)

You should adapt it, cause my box and wire are oriented to the LookVector not the RightVector

Works fine but not always… Still not working as expected if the hand is behind the center point of the wire… so ignore it…

We need someone to englight this a little. Or use Raycasting! xD

Do you want a place file with the pantograph for you to mess around in?

I’d love it, would be easier to test, but I still dont think I could find the answer Im not used to manipulate the CFrames in this way, as I suggested I prefer to just cast a ray and find the required Y coordinate that I need

Hey… but… and when the train is moving? the height distance between the train and the wire will change?. So this should be computed on a loop/RunService???..