# Rotate an object in all directions using the mouse

**URL:** <https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [April 9, 2020, 2:26pm UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545 "2020-04-09T14:26:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![BioMedKUL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BioMedKUL](https://forums.unrealengine.com/u/BioMedKUL)\
**Post date:** [April 9, 2020, 2:26pm UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/1 "2020-04-09T14:26:14Z")

</div>

Hi all,

I want to create a mini-game which start with a 3D object at the center of the screen. A user needs to rotate an object in all directions by using the mouse. Same as you would look at a 3D object in a web browser e.g. [like this one](https://sketchfab.com/3d-models/rexy-20-a204fb2cb3ed44c6a97355cb67a92946).  
After that, the user needs to be able to click on certain areas of the object (which I guess would be separate assets that are attached to the same object e.g. as components in a blueprint).

I can’t use the default templates since they always start from a user pawn (first person, third person etc).

What would be the best way to do this in Unreal Engine?

Thanks a lot for your advice.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 9, 2020, 4:18pm UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/2 "2020-04-09T16:18:59Z")

</div>

Rotating an object is rather straighforward:

 ![299372-rot.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/7/d/97db5b7d177e584d5cbf1b5091bcb21be90906d7.png)

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/8/7/8873edf5b553854f1ad466252295aee0a1bf9a5b.gif)](https://gyazo.com/f1e0aae3a4e579adf7cb83323e43e9a1)

> After that, the user needs to be able  
> to click on certain areas of the  
> object

_Child Actors Components_ sound like the most obvious solution if the attached elements need to define their own unique logic. Depending on what is required (complexity of the shape of the object, modularity, scope) you could have sockets on a static mesh and add Child Actors Components procedurally.

> I can’t use the default templates  
> since they always start from a user  
> pawn (first person, third person etc).

I do not know what this has to do with anything.

---

<div class="post-metadata">

**Author:** ![BioMedKUL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BioMedKUL](https://forums.unrealengine.com/u/BioMedKUL)\
**Post date:** [April 10, 2020, 6:31am UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/3 "2020-04-10T06:31:21Z")

</div>

Hi Everynone, thanks a lot for your answer. Just to be clear what I did: I created a blueprint of the object I want to rotate (aMouseRotate). From the level blueprint I cast to that object which is also in my scene. In the level blueprint, I made a variable (RotateThis) which is an object reference to that blueprint. Is that what I should do? You screenshot is a little fuzzy about that. When I play my level, the object is indeed rotating (kinda, it’s not really rotating around it’s z-axis but rather leaning to the left or right) but I’m also dragging my entire scene along (camera also moves along with the mouse cursor). How I can stop this?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 10, 2020, 8:55am UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/4 "2020-04-10T08:55:42Z")

</div>

> In the level blueprint, I made a  
> variable (RotateThis) which is an  
> object reference to that blueprint. Is  
> that what I should do? You screenshot  
> is a little fuzzy about that.

Apologies. Here’s a tad more thought behind the reasoning.

The code I posted will work in any blueprint. If you do use it outside of the _Player Controller_, you will need to _Get Player Controller_ for the 3 nodes that need it as a _Target_; the 3rd one being the mouse cursor visibility.

The script selects a clicked object so you can use it with _any_ object _anywhere_. If you already have a reference (as mentioned below), you can skip the left side completely and just use this:

 ![299396-untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/9/e/f9ed3243a5527da8f573332631751025f9162346.png)

You can even skip validation if you’re certain the reference is always valid. I’m assuming you’re attempting it all in the Level Blueprint. Generally speaking I’d avoid doing anything in the Level Blueprint that is not unique to that level. For example: if you load a different level for a different scene, you’ll need to rewrite the script. Again, it depends on how modular and grand in scope the project is supposed to be. If you never load another level, it’s OK to script in the LB. It still makes the communication a bit awkward at times, though.

* * *

> I’m also dragging my entire scene  
> along (camera also moves along with  
> the mouse cursor

It’s the default Pawn’s behaviour. Create your own Pawn, create a custom Game Mode and assign the Pawn to it. Finally, start using the Game Mode. This will give you a Pawn that does not have any functionality built in. More info:

> **[Setting Up a Game Mode](https://docs.unrealengine.com/5.3/en-US/setting-up-a-game-mode-in-unreal-engine/)**
>
> A tutorial for setting up a Game Mode in Unreal Engine.

You will need this anyway in order to control the flow of data. In addition, the framework classes mentioned above expose a lot of functionality and often serve as _glue_ between various elements of your project.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 10, 2020, 8:56am UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/5 "2020-04-10T08:56:56Z")

</div>

> From the level blueprint I cast to  
> that object which is also in my scene.  
> In the level blueprint, I made a  
> variable (RotateThis) which is an  
> object reference to that blueprint.

There’s no need to cast. If you have something in the Level Blueprint, you can reference it directly by selecting an actor in the scene and right clicking in the LB graph and choosing _Create a Reference To…_ Drag and drop also works in this case. But it does sound like you’ve done it already since you see things lean.

> it’s not really rotating around it’s  
> z-axis but rather leaning to the left  
> or right

Perhaps you can share a screenshot. We can try to troubleshoot.

---

<div class="post-metadata">

**Author:** ![BioMedKUL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BioMedKUL](https://forums.unrealengine.com/u/BioMedKUL)\
**Post date:** [April 10, 2020, 9:59am UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/6 "2020-04-10T09:59:28Z")

</div>

Hi Everynone, thanks for your clarification. I’ve updated my code (everything is inside one blueprint). I think that part should be fine. Thanks for that. The only issue that remains is that it doesn’t rotate properly. Here’s a .gif attached.

![299407-rotatingcube-small.gif](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/3/3/a33bf6254419ff73bd75a979cb134799a14b30ae.gif)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 10, 2020, 10:34am UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/7 "2020-04-10T10:34:41Z")

</div>

Looks like all you need to do is to reverse the +/- on the multiplier. Or use another axis.

---

<div class="post-metadata">

**Author:** ![DavidOConnor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/davidoconnor/32/978533_2.png) [@DavidOConnor](https://forums.unrealengine.com/u/DavidOConnor)\
**Post date:** [April 14, 2020, 9:00am UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/8 "2020-04-14T09:00:16Z")

</div>

ummm… I think it’s rotating around the cube’s pivot (on the bottom)… just put the pivot in the center of the box and it should be fine…

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 14, 2020, 9:19am UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/9 "2020-04-14T09:19:41Z")

</div>

I did not even notice that but you’re right, of course. Although the direction still looks reversed. Might be by design, though.

---

<div class="post-metadata">

**Author:** ![BioMedKUL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BioMedKUL](https://forums.unrealengine.com/u/BioMedKUL)\
**Post date:** [April 14, 2020, 12:19pm UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/10 "2020-04-14T12:19:01Z")

</div>

Thanks for your suggestions! I solved it by connecting the right nodes.

 ![299698-nodes.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/d/6/bd690f3f4d3a2d74309e160a7c3a34fd245b67de.png)

I also had to add “Set Input Mode Game Only” in the level blueprint to be able to interact with the object.

---

<div class="post-metadata">

**Author:** ![BioMedKUL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BioMedKUL](https://forums.unrealengine.com/u/BioMedKUL)\
**Post date:** [April 15, 2020, 11:11pm UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/11 "2020-04-15T23:11:51Z")

</div>

Solved it by connecting DElta X (value -10) to DElta Rotation Z and Delta Y (value 10) to Delta Rotation Y. Also had to add “Set Input Mode Game Only” to level blueprint in order to make it work.  
For those interested: I also found another solution where you rotate around the object, instead of rotating the object itself. Both can serve specific purposes: [UE4 Camera Rotation Bueprint - YouTube](https://www.youtube.com/watch?v=CVIv3KEjcdA)

---

<div class="post-metadata">

**Author:** ![Rishi\_Jayanthan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rishi\_Jayanthan](https://forums.unrealengine.com/u/Rishi_Jayanthan)\
**Post date:** [August 2, 2021, 11:11am UTC](https://forums.unrealengine.com/t/rotate-an-object-in-all-directions-using-the-mouse/463545/12 "2021-08-02T11:11:27Z")

</div>

hey guys, how to do this exact same thing with touch input? the object have to rotate based on the touch movement on the screen(swiping). Could somebody give a solution?
