No announcement yet.

Sidescroller with asset aiming towards mouse position

  • Filter
  • Time
  • Show
Clear All
new posts

    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:

    I've made a couple of attempts to best replicate this effects but to no avail.

    The first one doesn't rotate around the characters at all while the second only works in a limited range

    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?
    Unreal Possibilities
    Wave Spawning System | Tower Defense Starter Kit | Floating Damage Texts


      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 BP I'm using is working great, but there is a noticeable snapping with aiming directly above. I'm hoping to have version that rotates as seamless as possible.


          This was the video I followed:


            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;

            my portfolio
            my youtube

            Camera Volumes System
            Instanced Plugin
            Simple Portals
            Water Flow For UDK
            Setup Swarm