I’m developing a little demo wherein I place two spheres and a cylinder. I’m trying to make the cylinder act as a sort of bridge, or connection between the two spheres. I have added a little Blueprint that makes the spheres move up and down independently of each other. The part I am struggling with is that the cylinder should then follow both spheres, and be placed in between them both. The angle of the cylinder should be so that it is pointing from one sphere to the other no matter which sphere is moving. I have added a little sketch of how the movement would look.
Subtract the two sphere’s world location -> Normalize.
Use there world locations to get the distance between them.
Divide the distance by two and place your cylinder there.
Rotation: I am not sure. - You could try traceing between the two sphere’s and using the contact normal for rotation.
I forgot: The first part (Subtract the two sphere’s world location -> Normalize) gets you a move direction vector, There should be a way to get a rotation out of that(As Eular angles anyway).
HTH
Edit:
If you want I will see what I can do.
Perhaps you could post the end result (Blueprint or description of what you did) for other people to see.
So I tried fiddling some more with the blueprint and got this:
It’s still not rotating as I want it to, so I’ll just have to try some more, but I’m quite new to Unreal Engine 4 and haven’t done vector calculations in 2 years so it might take me some time.
I have found this stackoverflow post that walks about rotating an object to face a point.
Last night I got to thinking about having N spheres with the cylinder in the middle of them.
The algorithm (untested) is to get the halfway point between each sphere and use that point for the place of one sphere, But rotations would be a problem along with weighting the placement.
I think I will give this a shot, For reference my cylinder will face up(so you may need to use an offset for rotation).