Need help with Piston motion in Unity!

I am currently trying to ‘simulate’ a piston in unity, the piston end (part B) is attached to a main frame which rotates (part C), the piston base (part A) is fixed to a static object and also rotates (green dots are rotation points)… here is a drawing of what im trying to explain!

Basically im trying to have part A and part B stay on the same plane as part C rotates upwards, is there a way to do this? Maybe have part A ‘point at’ part B’s rotation point (green) and part B ‘point at’ part A’s rotation point (green)? This would keep them on the same plane, if its possible?! :face_with_spiral_eyes:

This would save me a great deal of time trying to rotate each part individually tryig to keep them lined up as part C rotates upwards!

Thats for any time and input! :smile:

There is no built in way to do this. You have to script it. It should be just a couple lines of code as long as you place your pivots correctly.

Hi Paulius,

I have figured a way to do this very well. All i needed to do was use the transform.LookAt() for each part, part A looks at Part B and part B looks at part A, simples!

Thanks

I’m trying to do the exact same thing, but LookAt apparently does not help me much. May you share your code so I can check the difference with mine? When I put my objects in a hierarchy, all the system stops behaving like expected.

Thank you very much!