Download

Convert Mouse Location to World Space with tilted camera

Hey everyone.

Just quickly, i have been trying to sort this one out for awhile now but yet i am not having any luck at all.

I am following a really good tutorial online which goes through how to set up a top down shooter.

The game I wish to make is similar, however, instead of top down (direct 90 degree rotation of the camera), it has a tilt of -60.

Now my problem is that when i apply a ‘Convert Mouse Location to World Space’, my character in game only rotates from a value of 175, 180, -175. However, when i tilt my camera back to -90, it works perfectly.

I am currently using the ‘Get Hit Result Cursor By Channel’ with the exposed Break set to ‘Location’, then fed back through to the Find Look at Rotation. However, using this is fine and all, and works great… until something obstructs the view (it tends to jump ever so slightly). For example; for the location of Y= -31, as soon as I go over an object, it jumps to Y=-38 (with the character jumping in between rotations).

I have tried using the fantastic Macro that Adam has provided (and can be found on youtube) - https://answers.unrealengine.com/questions/16847/request-ray-plane-intersection-point-function.html

However, I still get the same result

Now my camera/SpringArm/Defaults settings are all set to ‘Relative’ (I have even tried world and still doesn’t work)

Was wondering if there is a work around with this or a straight up answer, that would be much appreciative. Here is the blueprint for the Controller at the moment:

f94e43fa4146bd21dd57d1b90a24b9d084037ea3.png

And when i apply the ‘Convert Mouse Location to World Space’, I get this:

0f2a932d30324d42c09b93825aa0757e65199551.png

In this above image, im moving the mouse around everywhere (and getting values only from 175 - 180 - -175) but its just hard to replicate :S. Please help guys, I’m not sure what’s going on- Also, I want to try and avoid scripting C++ as much as I can, and stick to visual coding (Blueprints).

Cheers

and here is the result of Convert Mouse Location to World Space

3858b51ff5447e113280a0a4e49ed3a2019287c7.jpeg

In this above image, I’m moving the mouse around everywhere (and getting values only from 175 - 180 - -175) but its just hard to replicate :S

You are using only World Location of ConvertMouseLocationToWorldSpace which is not enough. Take into account World Direction as well, as when you camera is at 90 degrees pitch, World Direction is simply (0,0,-1) vector. To take into account tilt of your camera, your actual intersection point would be World Location + World Direction * {some distance from camera into the world}. For the matter of fact not only tilt but position of the camera affects this as well.
I have a similar functionality in my project and what I use is GetLineVsPlaneIntersection (don’t remember exact name of the node), which I feed [World Location] as a start point and [World Location + World Direction * 500000] as end point. Another parameter for the plane is it’s height above some axis, you can set it somewhere above the ground. This will give you a point in 3d space where your mouse cursor intersects a plane and it won’t be obstructed by other geometry.
I can show you a blueprint when I get back home, if I don’t forget about it :slight_smile:

…and this is how you can do it:

Mouse_Plane_Intersection.PNG

GetActorLocation() can be location of you character and you get intersection with a horizontal plane (plane normal is 0,0,1) around him.

I didn’t know this could be done that way, thx for sharing :slight_smile: (pictures are great !)

Thats great! However, he just seems to rotate according to the plane center instead of himself. This is what i have so far:

Char_Mouse_Rot_Issue_Result02.png

Mmm, but he is suppose to be at the origin of the plane, I’m not sure why you add -80 on Z.
Anyway, I think “Rotation from XVector” requires a unit vector, try to normalize Intersection vector before you pass it to “Rotation from XVector”.
Or replace “Rotation from XVector” altogether with “LookAtRotation” and pass it Pawn location as start and Intersection as end. If I recall correctly Intersection is calculated in world coordinates, so it should work.

Hey guys, thank you all for posting on this, however i think it may be better just to ray trace the collision of the ground instead (using the ‘Get Hit Under Cursor for Object’

1bb64727e3cc5e879e8bba664b98bb21f572e81d.jpeg

Thank you thank you thank you. The original solution didn’t seem to be accurate for player movement (although I don’t 100% understand why we are multiplying by -1, so that could have something to do with it). This method is much more accurate. Much appreciated!