Download

Sidescroller with asset aiming towards mouse position

Hello! I’m trying to build a sidescroller that moves a character to the right of the screen and left, but most importantly an arrow that aim towards the mouse cursor’s position on the screen. The best example I can think of is Metal Slug’s tank: https://youtube.com/watch?v=XJi9MmLHp7c

I’ve made a couple of attempts to best replicate this effects but to no avail.
[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_170614_1565466089923_103”,“title”:“convertmouselocation.PNG”}[/ATTACH][IMG2=JSON]{“data-align”:“none”,“data-size”:“full”,“src”:“https://forums.unrealengine.com/core/image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==”}[/IMG2]​
[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_170616_1565466161672_805”,“title”:“rotation_attempt.PNG”}[/ATTACH][IMG2=JSON]{“data-align”:“none”,“data-size”:“full”,“src”:“https://forums.unrealengine.com/core/image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==”}[/IMG2]​
The first one doesn’t rotate around the characters at all while the second only works in a limited range
https://youtube.com/watch?v=_RWlaFJfgs0
Any help would be greatly appreciated! I’ll continue to find to find a solution!

Hi, are you having trouble finding the exact cursor location on the character’s movement plane, or with rotating the arrow towards it?

Rotating the arrow towards it. I found a solution, but it is a bit limited. When the arrow is close to 90 degrees aiming above the character its snaps about 5 degrees to the opposite side. I’m at work atm, but I can follow up later with a screenshot of my blueprints, the video I followed, and the results.

This was the video I followed: https://www.youtube.com/watch?v=uZBYB3K0OX8

use vectors.

(world_mouse_position - world_gun_pivot_position).normalize() - this will be direction of gun orientation in world space.
where world_gun_pivot_position is point where gun attached. in world space. it should be like local_gun_pivot_position + world_vehicle_position.

then convert direction to rotation using one of MakeRotFrom* functions, depending on your coordinate system.
and set gun rotation in world space.

to use local position, relative to vehicle position, simply subtract vehicle position from it:
local_mouse_position = world_mouse_position - world_vehicle_position;