Need help with a DragCamera function for my camera system

I’m working on an RTS camera controller. I have everything working except one bug that I can’t seem to figure out. One function of the controller is that I can hold the mouse wheel button and drag the mouse around and if I drag the mouse down for example, the camera moves up the screen, if I drag the mouse left, the camera moves right. This works fine when I first start, but as I move further away from the worldspace origin, it starts to behave incorrectly, where down moves the camera to the right instead, and up move the camera to the left. I think it may have something to do with how I’m doing the ray or plane in the provided function, but i’m not positive. Any help would be great! Thank you! DragCamera function posted by ethancodes | blueprintUE | PasteBin For Unreal Engine

Agreed, try it like so:

How do you get that multiplication node with the single value on the bottom? Sorry, fairly new to UE and I’ve not seen that before.

This is new to a lot of folks - it’s a UE5 specific feature:

You can right click pins and change their type.


This is new to a lot of folks - it’s a UE5 specific feature:

Existed in UE4 but was in its infancy.


It still needs to make sense, ofc. Some things just don’t:

But it is clever enough:

Ah ok, thanks!

Well, I made these changes, and it certainly did something, but whatever it’s doing is causing the value returned from the intersection to increase drastically with very little movement, throwing my camera way off into the sunset. lol. Do I maybe need to scale that value down or something?

Can you show how the whole is set up right now? What I suggested was just a part of the whole thing. May need adjusting. Technically, it returns a world coordinate the camera should be able to vInterp to.

Not sure how you do that bit, a wild guess.

Yea here’s the updated blueprint. I’m not sure what vInterp is, I’ll check it out.

if it helps at all, I’m converting this over from Unity and this was my original code in Unity.

private void DragCamera()
    {
        if (!Inputs.DragCameraIsPressed)
            return;

        Plane plane = new Plane(Vector3.up, Vector3.zero);
        Ray ray = mainCamera.ScreenPointToRay(Inputs.MousePosition);

        if (plane.Raycast(ray, out float distance))
        {
            if (Inputs.DragCameraJustPressed)
                startDrag = ray.GetPoint(distance);
            else
                targetPosition += startDrag - ray.GetPoint(distance);

        }
    }

Finally fixed this. Just needed to scale down the change in location vector. Not entirely sure why though… so if someone understands it better than me, I’d love to know! here’s the blueprint: DragCamera function posted by ethancodes | blueprintUE | PasteBin For Unreal Engine