Help with finding distance to actor edge


I’ve been working on this for about a day now so hopefully someone can help a bit. I have flat square surface with a picture on in floating in the game work. I’m trying to find the x and y location of the click on this flat surface with the top left location being (0,0).

As of right now I’m doing a trace to the surface from my character and then calling GetActorBounds on the surface that I click on. The problem is that the actorbounds change depending on the actor’s rotation. Based on the pitch roll and yaw I’m getting varying values for my (X,Y) click position.

if (actorRotation.Yaw >= 0) {
	xpos = (actorBounds.Y - clickPosition.Y) / (actorBounds.Y * 2) * compscale.X;
	ypos = (actorBounds.Z + clickPosition.Z) / (actorBounds.Z * 2) * compscale.Y;
else {
	xpos = (actorBounds.Y + clickPosition.Y) / (actorBounds.Y * 2) * compscale.X;
	ypos = (actorBounds.Z + clickPosition.Z) / (actorBounds.Z * 2) * compscale.Y;

The above code is rudimentary and flawed. It works if Yaw is 90 or -90 but if roll changes or yaw changes the value changes.

What is the formula for getting pixel perfect x,y positions? I’ve already tried every combo of sin and cos that I can think of but doing so just throws it off even more.

Help would be appreciated.

If I understand you are trying to get the mouse click location on an object in your scene that is a flat surface. Is the surface view aligned? What does the character have to do with the equation?

If you have the XY position of the click in screen space, it should be pretty trivial to translate to an XY position on a flat polygon in world space. How does the character fit in?

Not much besides using a trace from a character to the surface. I do have the location of the point on the flat surface in 3d space but I don’t know how to find the xy location as the surface is rotated every which way. The surface view is not aligned btw.

Eliminate the character from the equation. You know your camera position, your click xy in screen space, and your flat surface position and orientation. I can’t mentally walk through it right now, but I know that’s all the info you need to find where on the surface you are clicking. You shouldn’t need to even use a trace to work this out.

Thanks for the tip but I’ve been trying to walk my way through it since 9am this morning Cali time. I’m not giving up but I have little hope of figuring this one out. I’m missing some kind of fundamental information.

Look up DeprojectScreenPositionToWorld. Seems that should get you 90% of the way there.

In every function that has to do with this the origin is already in the top left of the viewport. What if your origin is in the center of the surface that you care about?

It’s blueprint but easy enough to translate to C++

This seems really close to what you are trying to do, it might help. Instead of using the camera, on mouse click convert your mouse position to world using DeprojectScreenPositionToWorld. It is supposed to come with an aim vector you should be able to trace. Use the impact point from BreakHitResult.