• News

• Industries

• Learning & Support

• Community

• Marketplace

# Actor Movement Based On Other Actors

Hi!

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.

I would like for this to be axis independent, so that it doesn’t matter if the movement is on the X, Y or Z axis, or a combination of them.

All tips and solutions are much appreciated.

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.

HTH

Thank you, I got that part working now!
I’ve been trying to do the rotations using vector calculations, but it seems that I’m still doing it wrong.

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).

HTH

I found this answer on rotating to point

Wow, thank you so much, it’s now working perfectly!

Here’s my end-result for people who need it: