Download

How to make an object always face the user's cursor?

Hello all,

I am making a game where I have an arrow that has to always face the user’s cursor. Here’s how the game looks right now:

Frankly, I have no clue where to start in doing something like this, and I would highly appreciate some help. The version of the Unreal Engine that I’m using is 4.22.3.

The world is 3d and the cursor is in 2d space.

1 Like

Assuming it’s the latter as it’d make more sense, you could try this:

This, ideally, should be in the Player blueprint or the Player Controller but can, technically, live anywhere.

Edit: forgot to add that the arrow needs to be in the Absolute Rotation mode:

However, you’ll, most likely, want something with a wee bit more ooomph than an arrow. A spline + spline mesh component could work nicely and can be used to visualise an arc of a lob, for example.

1 Like

Thanks very much, this helped a lot.

Here’s a video of what the game now looks like:

As you can see in the video, the arrow makes a weird rotation whenever my cursor goes to certain areas. To combat this, I can try to constrain the arrow’s rotation to a certain range (the goal area). Once again, I am not so sure how to do this, and would appreciate some help!

That’s normal with this technique, we’re tracing from the camera into this green plane. The intersection cannot be resolved if the trace does not hit the plane.

Your request is quite unclear at this point. Do you want to trace against the geometry instead - as in the wall in the background? Do note that the cursor is in 2d and you want to interact with 3d world. You need to take that extra D from somewhere.

Do you only need to perform this test ahead of the player? Perhaps you could describe the gameplay goal? Are we shooting penalties, aiming with the cursor?

1 Like

Ok, I’ll try to clarify what I mean, and if it doesn’t work, we’ll figure out something else. What I’m trying to do is have some kind of max mouse X, min mouse X, max mouse Y, and min mouse Y values. These values will represent the bounds of the goal, which I still don’t have. If the current mouse location doesn’t correspond with these min and max values, we don’t rotate the arrow and keep at its rotation before the mouse was moved. Now that I’m writing this down, implementing it seems easier that I thought. Unfortunately, I am currently away from my computer, so I can’t quickly test this out. Before I soon do so, though, do you think what I’m saying makes sense and would work?

Rather than trying to figure out an arbitrary frustum projection, it sounds like it’d be easier to just:

  • new object type

This will work with goal of any size and at any distance.

1 Like

Thanks so much for your quick replies. I will try this out as soon as I get home.

1 Like