Hey there, hoping I can get pointed in the right direction on this.
This is assuming a 2D Side-Scrolling Game, running horizontally on the X axis, and jumping/falling on the Z axis, with the Y axis used as depth. I’m wanting to make a point-and-shoot kind of component (for hopping in a flak gun of sorts and firing rounds that explode a the mouse cursor to give an AoE effect). I already have it just fine so in regular gameplay, the rotation follows the mouse and is constrained by degrees of pitch and can have aim/firing offsets depending on the weapon held. What I’m a completely stonewalled on is that I need to find the coordinates of the mouse in world space, but with the Y value (used for depth) locked to the player’s Y coordinate, and X/Z being determined by the mouse position on the screen.
I could cheese this by making a large plane that is only there to pick up line trace hits and then use that hit location as the location for target effects, but that feels verrrry much so like a duct-tape and chewing-gum remedy.
Any help would be greatly appreciated, and I can give more info if needed.
So you can use “Get Mouse Position”, and pass that into “Convert Screen Location to World Space”, break the “Screen Location” Vector, and use Create Vector to get the position just right
Let us know if you want a more in-depth explanation!
In my case, it’s using world y as left/right and x as depth, so you’d half to swap those and adjust the origin (I just constrained everything to x64 so the navmesh is cleaner lol).
I’ve dabbled with screen location to world space, and it has…weird effects (at least at my little understanding of it all). If I replicate your steps exactly (with a slight twist of just plugging in the XYZ and using the Y coordinate of the player) then pass that on to a Draw Debug Sphere at the center being those values, it just hovers at my player’s location, moving only slightly (I’m guessing a +/- ratio relating to its position on the screen space).
Just used your method and YES the Line Plane Intersection is EXACTLY what I was looking for! You’re the man, thank you so much. Now on a plane extending outward at the depth of my player’s Y location, I can aim from the camera component so that at the point of intersection there is a readable, usable location vector.
Glad it worked for you. Another fun bonus of the intersection thing is you can move the plane rather painlessly without worrying about a real line trace intersecting all the things. Like, if you wanted a giant boss that’s in the background or something, just move the origin when the encounter starts.