Player places objects on walls - how to get proper rotation of objects

Hello everyone!

Sometimes the object turns out good, then again on other walls (which are facing different directions) the object is rotation wrong, behind the wall etc…

My first try on this was to use the camera rotation in relation to the wall im currently looking at. Way to complicated.
My second try was to add invisible arrows to the wall and I place the walls in a way that they always look in a certain direction (to the player) This is possible since the player will always see the wall from just one side. Then I read the world rotation of this arrow from the wall I currently want to place the object on. Worked kinda… but even if the rotation was correct the object was still not placed on the wall but behind it for example.

Im pretty sure there is a very easy solution to this, hopefully you guys can help me out :slight_smile:


Something along these lines?

Not sure if there’s an easier way:

Can me made more complicated, for sure.

Hi @Everynone

thanks a lot :slight_smile:
I do work in first person view, so I changed to the line trace break hit result and a different axis. Seems to work! Much easier than my stuff and much less code :slight_smile:

Do you mind explaining what happens here?
Is “Normal” the same as in 3D work, so the face orientation? If so, then its taking the normal axis and equals this to the rotation of my object?

Thanks for your time :slight_smile:

Yes, and in this very case we ask the object to stand up (Z) on that surface. If you were to hang a painting, you’d most likely want rotation from X (or -X to flip it). If you were to attach fins of a radiator perpendicularly to the wall, you’d opt for rotation from Y. This, of course, depends on which direction the mesh / actor is facing in the first place.

Hey again @Everynone

Mhh I see.
Can I somehow use this normal information to “snap” my object on the face of the wall? I have issues with the distance from my object to the wall.
I currently use your normal information to read the axis, then 4 branches for each axis (x/y/-x/-y) then manually substracting/adding floats to make it suit nice to the wall. This would be okay for one object, but obviously a nightmare for more/different objects.

Your time in this thread is much appreciated … thanks!

Doing it manually is a no go in most cases, true. You have options here, though:

**- ideally: ensure the meshes have their pivots at the base and always face X - this way they will never sink into other geometry

  • alternatively, you can offset the static mesh in the editor by attaching it to a root / another scene component, this is my torch:

Above: the static mesh’s scale Z is 1, I know this mesh is 50uu in Z; if I punch in +25 in Z location, the torch will be offset perfectly with its base touching the ground when I make rotation from Z and plop it on any surface.

  • you could use static mesh component’s bounds as the offset, it spits out a radius float equal to the half of the largest dimension in either XY or Z; while it would work for anything oblong that needs to stand up, it would not work for a car that’s rolled over to its side. Not without extra work, that is.
  • there is also a somewhat involved technique useful when dealing with irregular (regular, too) shapes at precarious angles. What is known as *Sweep *in UE4 allows one to find a location where an object *would *start overlapping. Think of pretending to drop something onto a surface and attaching it where it touches it. Sweep can find the first contact point and final resting location. You’d need meticulously crafted collision for that to work precisely, though. [HR][/HR]
    Not sure what you need this for so hard to advise. The first suggestions is generally a step in the right direction. Who knows, you might be attaching torches to walls or bombarding monsters with spiky blobs - you’d need a different method for those.

edit: You did say objects on walls, so fix the pivots and you’re done.

Hi @Everynone

offtopic: do I have to @you like this that you get a notification? And how did you made this video in quick way? Might be helpful to actually showcase issues in the future.

Back to topic:
Oh boy did I struggle with that. Manually adjusting the location of the object now works thanks to your normal - make rotation. I forgot about that and tried severely different things before I realized :smiley:
The result now is perfect and works on every axis / different wall like a charm.
But I do had to rotate my object in the blueprint like crazy, see in the image. This way, when I place it ingame. Green is actually the bottom and blue the top (how it should be).

In Unreal: Red is Forward, blue is Up and green is Right. :smiley:

Double click that Arrow Trap static mesh and check against the coordinate gizmo in the bottom left corner:


Above, top-down view of a camera.

Whoever designed that arrow trap had a specific use in mind, exported it mindlessly, and / or the exporting software was set up incorrectly for UE4 use.

It helps but I’ll see it one way or another.

I use a free version of Gyazo - Download for this; it records 7 seconds of whatever I select on the screen, opens the browser and spits out links:

Annotation 2020-07-22 163039.jpg

I opted for this as it takes the least number of clicks, and I do not need to store anything locally.

Alright, thanks for the information! Very helpful.
I made the ArrowTrap in Blender. Looks like I need to check the export settings then :slight_smile:

Right then, I’ll take my coat… ;|
It’s a great looking asset, actually! Would walk in.

Hahaha made me laugh out loud :smiley: thanks mate

Update: Alright, after changing the export settings in Blender everything is now working as intended :slight_smile: No weird adjusting to the rotation neccesary anymore.
Thanks for your support during this crisis :smiley:

10/10 - would walk in again