# Rotating an Actor in Game

Hi, I’m trying to rotate a non-player pawn in my game. I am using a LineTrace to see what actor is in front of me. I want to be able to rotate that actor upon hitting a key or a combination of keys. Is there any way to do that?

Yes, it’s relatively simple.

1. Use your line trace to get the actor which you’re looking at.
2. Verify that the actor is of the type which you want the player to be allowed to rotate (hint: use “Class Of”)
3. Get the actors current rotation by using “Get Actor Rotation”
4. Add a delta rotation by using “Combine Rotators” node
5. Apply “Set Actor Rotation” to the actor and feed it the combined rotation value

You can bind a key press event to trigger an event within a rotatable actor. You can either use blueprint interfaces or create a function and cast your actor to the specific blueprint and then call that function.

Thank you for the help!

Sorry if this sounds stupid, but what would the delta rotation be comprised of? Still kind of new to the whole blueprint stuff.

It would be the change in rotation over the change in time you want to use to rotate the actor by. An example would be something like 5 degrees per second. If at Time 00:00 the rotation is 0 degrees, then at time 00:01 it would be at 5 degrees.

So I would use the Delta Seconds variable from EventTick in order to tell the difference in time, then multiply that by the axis value from the inputAxis, and create the delta rotation based off of that?

Not quite. The input axis will give you a number which ranges between -1 and 1. Use this to multiply your delta rotation, so that you’d get something between -5 and 5 (respectively). Then, multiply the change in rotation by your delta time (you’ll get a much smaller number). Then, apply this change in rotation to the selected actor. If you want your actor to spin faster, just increase the delta rotation value (rotation rate).

So I tried it out and this the blueprint I ended up with. Unfortunately it does not work. Any idea of what’s wrong? The Hit Actor variable is the actor that I hit with the LineTrace, the DeltaRotation is a float value of 5, and the DeltaTime is just EventTick’s delta seconds.

This node network looks correct at first glance, but the truth is in the data. It’s time to put in a bunch of “print string” nodes and see what the actual value outputs are compared to the expected output values.

I figured out the problem, I hadn’t hooked some things properly. It works now