This might be a dumb question… but how can i rotate an object based on a linetrace to the surface it hits?
Assuming we want to align an object with the hit surface, one can make rotation from surface normal. This is returned by the trace.
If you have a chair whose Z is up, you’d make rotation from Z. But you may have a torch (Z up) to place on the wall instead, then you may want to choose another axis. But that’d depend on how it was modelled and how the axes were assigned when exporting mesh from the modelling app.
How would i go about it, if i want the object i am trying to rotate keeps its rotation directions no matter what?
Even if i tilt the object to the surface the x y or z still keps the same direction the current object is facing?
Hope that makes sense
This sounds as if you did not want to rotate it. Perhaps you want to align it with trace direction rather than the surface it hits?
Other than that, we’re gonna need a diagram. We’re talking about rotating it one way but keeping a rotation in some other way. So I am officially lost.
You can make rotations from more than 1 axes:
This would generally get rid of any ambiguity.
Okay so,
The red X is the line trace, Yellow circle is the object i want to move and the green arrow indicates the direction based on the line trace
If you take a loot the yellow chair, it has a rotation. Now if i want to rotate that but still keep some of the rotation like how its angle but still have it rotate in the green direction so its like the chair is stuck on the wall
You want to treat the line trace hit as the pivot of the new rotation, like a hinge?
Not sure what you mean, but using the first sample “Make Rot fro X” does kinda work. Problem is that it shift the whole rotation.
I dont really know how to explain it, but i can do my best
If you take a look at the yellow chair, it already has a rotation. Now if i want to rotate that chair in the direction of that arrow how do i caluclate the rotation for that? Reminder, the current rotation can’t just go to snap to 0 and then a value so its facing along that green surface/red linetrace hit
I think this is a pretty good video that shows what i want, beside the fact that i am using a linetrace from my mouse
That’s rotation from Z since a character’s up is Z. My first post. If you want to account of the actor’s original orientation as you flip it around, it will be a matter of combining rotators.
Experiment with that, do note that the AB order matters greatly there.
Now, if you’re doing this to a chair, that should be straightforward. Making character gravity is very different.
Im more lost than ever… haha
I have 0 ideas on how to approach this even after alot of research
would appricate it alot, if someone could help
Still learning and keep learning here <3
Anyone?
If anyone is still confused with what i am trying to archive, please let me know
Consider creating a before and after example of one of those:
What you’re trying to do might be straightforward to achieve but a nightmare to explain. I did not get any of the explanations, but that might be me…
Do you really mean a ‘line trace’, or a ‘mouse drag’?
If it’s just a line from the camera to the X, how is the editor supposed to know you want to rotate the chair?
If it’s a mouse drag, then yes, maybe we can work with that…
Its a line trace, Im trying to rotate an object onto a surface based on where the mouse is
But as @Everynone Said, i’ll try to make some sort of visual demonstration
So you want to rotate the chair onto that surface behind it? ( the one you traced to )
Okay,
So if you take a look at this video Unity3D Building and Object Placement & Rotation. Let your players build the world! - YouTube and start from 11:42
You can see that the object is moving with the mouse and alligns it to the surface of in this case terrain but that could by anything like a wall or anything else
Anyway… If you also observe how the facing of the object isn’t changeing but it still does allign with the surface
So basicly
I want it to allign with a surface but still keep its facing direction if that makes sense?
Mhh kinda Works until i get a very high slope/a surface that is very steep
It changes the direction of the object if its too steep
One way to combat this (most likely) is to rotate the mesh component in its local space only. And then apply actor rotation as above.