Trying to place actor on walls/floors via line trace but keep getting the wrong rotation

I am making a little “Portal” project where I am trying to replicate the mechanics of VALVE’s “Portal” game and I am currently trying to write the logic for placing portals on walls/floors (via line trace, essentially “shooting” them unto a wall). The position ends up being correct but the rotation is wrong.

It’s kind of hard to explain the issue so I recorded a video to showcase it: - YouTube

In the video you can see that the portal has the same rotation when placing it regardless of where the player is standing. The correct behavior I want is for the bottom of the portal to always face the player while still remaining flat on the ground.

Here is my current blueprint logic: https://i.imgur.com/t7DjzVP.png

I know that I need to somehow rotate the portal in one axis to face the player so that it still remains flat on the ground… I just can’t seem to figure out how. I have tried multiple solutions but have never gotten it to work the way I want to. Help?

EDIT: BlueprintUE link for the whole BP event - Portal placement (WIP) posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

EDIT 2: A lot of people seem confused over what I actually want to do so I gave a more in-depth explanation in a reply comment to @DxDen1004’s comment. Please read it if you’re not 100% sure you understand :slight_smile:

Hi, could you please upload the full Blueprint here? It would be helpful to understand better how you are approaching the problem. Anyway, I think what you’re trying to do requires the Blueprint script to update your portal’s rotation continuously, maybe using the EventTick event. I suppose right now the SetActorLocationAndRotation node is only executed once and hence the portal’s rotation is only updated once.

While I await to hear back from you, I wish you a nice day.

Impact normal looks like the right thing. But it’s going to rotate around the Z axis to face the camera, right?

I added the full blueprint event now in a post edit. There isn’t much else to it to be honest.

I don’t want to update the rotation continuously. I just want to place it on the ground and have the bottom of the portal face the player (while still being flat on the ground). I made a (■■■■■■) picture in Paint to illustrate what I mean: https://i.imgur.com/fhdRKdJ.png . It is drawn from a top-down view. The red arrow is the direction that the player is facing and the blue arrow is the direction that the BOTTOM of the portal is facing.

I can get the portal to face/“look at” the player using the “Find Look at Rotation” node. But the portal is slanted as the face of the portal is pointing directly toward the player. I need to find a way to rotate the portal so that it is laying flat on the ground but still having the bottom of the portal point toward the player. I made a second picture in Paint to demonstrate this https://i.imgur.com/QdhsEcv.png. This is drawn from a side view where the thick black line is the ground/surface where the player tries to place the portal, the blue line is the portal and the red arrow is the forward vector of the portal while the green arrow is the down vector of the portal (the negated up-vector). The left-hand side of the picture is what happens when I use the “Find Look At Rotation” node and the right-hand side is the result I ACTUALLY want.

Important to note,the solution should work for ANY surface (ceiling, walls, angled surfaces etc.), not just the floor.

I hope my explanations aren’t confusing you. I tried to explain the best I can.

Actually, in hindsight, you’re probably correct. When the portal is on the floor/ceiling I want to change the roll (Z-axis) of the portal so that the bottom of the portal faces the player.

thats quite simple: from the break hit result connect:
Location->make Transform (location)
Normal->MakeRotFromZ->make Transform(Rotation - same node as step above)
use the output of the makeTransform for the transform of your portal. You may like to offset it with adding a vector to the location before going into the makeTransform node

Nope. That didn’t work. It just produced the same result as before but worse (portal ended up being perpendicular to the ground instead of laying down on it).

I tried multiple “MakeRotFrom___” solutions and none of them worked. Even if it did end up working I suspect using “MakeRotFrom__” will make it work only for surfaces with a specific angle (might work for floors, but not for walls, ceilings, angled surfaces etc.). I need a solution that works for any surface (read my comment reply to @DxDen1004 for more info).

just rotate it 90 degrees :wink: but it should give you the rotation which your hit actor has on the side you’ve traced. like it should work on a ground and even on angled surfaces, I thought this was the point of your question

It doesn’t though. If I rotate it 90 degrees it is flat on the ground, yes, but the BOTTOM of the portal (the negated up-vector of the portal) does NOT point towards the player. Nowhere in your solution is the player rotation taken into account, so it can’t be correct.

I think you have misunderstood what I want to do or I may have explained it poorly. As I said in my previous comment, read my reply to @DxDen1004’s comment for a deeper explanation of what I actually want to do.

Yes… but no. I want it to rotate around the normal vector of the surface it is placed on, not the Z-axis (Z-axis rotation gives an incorrect rotation if the portal is placed on something other than a floor. A wall, ceiling or any other angled surface).

A lot of people seem confused over what I actually want to do so I gave a more in-depth explanation in a reply comment to @DxDen1004’s comment. Please read it if you’re not 100% sure you understand :slight_smile:

Using MakeRotFromZ always puts the portal at the right angle relative to the surface ( floor ceiling etc ), but then I can’t get the lookat to work… ( the look at just needs to make a transform of the Z relative )

I managed to solve it myself. Here is the final blueprint for the rotation:

This only works for floors and ceilings. For walls and any other angled surface I use the rotation output from the “RotationFromXVector” node instead.