Rotate Mesh on MouseClick

Hey,

Am currently working on adding a turret I made, so far I’ve got it imported and I’ve followed this tutorial to figure out how to be able to look left/right and up/down. It’s been going pretty smooth so far, but I’ve hit a dead end.

Basically what I’m working on is a Phalanx CIWS. I’ve added an InputAction for LeftMouseButton, and I’m trying to figure out how to make the barrels*(it’s a StaticMesh)* rotate as I click the left mousebutton.

It might be worth noting that I am new to working with UE, and this whole FlowGraph thing is new to me. If anyone has some advice or pointers, I’d greatly appreciate it.

Example of what it currently looks like, if it is of any help;

So assuming the barrels are a component of that Phalanx thing, you’d simply drag that component into the Blueprint and do a rotation on it, something like this:

Inside the Timeline it would look something like this:

Basically a key at 0 secs and value 0 and another at 2 secs (or whatever to achieve the desired speed) with value 360. Set it to looping and the same length as the second key.

Okay, now it does something. The barrels don’t spin, though. As soon as I click the mousebutton, the camera rotates 180 degrees and if I try to look around whilst holding it down - it just goes bonkers. Might it have something to do with the fact the camera is a child of the barrels?

You’ll get used to it and find it actually makes a lot of sense. You want to set the rotation of you barrel, so of course you would drag out from that and see what’s available. You will then only see relevant nodes that will actually work for your component. So first think of what you want to manipulate, get a reference to that and then find about how you can manipulate it.

If you attach the camera to the rotating barrel, the camera is going to spin.

I tried attaching it to the Turret part instead, and it was better. However, so long as the mousebutton is held down - the barrel does not follow the rotation of the turret. Suggestions?

SetWorldRotation sets the barrels rotation in world space. You want SetRelativeRotation, and then on just the axis the turret spins around.

Ah, that makes sense… Thanks for helping a rookie out guys, I really appreciate it! This timeline sure will come in handy, will try to use it for my sound assets as I was trying to use timers at first, but couldn’t get it to work.

Did you get it working?

Aye, it’s working. We’ve got spool up and spool down working as well!