system
1
|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
wowzzers |
What is the correct way to align a newly created mesh instance, like a decal, with raycast result’s hit normal along the Z axis?
I’ve created this questions some time ago, but the solution doesn’t work now.
https://forum.godotengine.org/42265/how-to-align-an-instance-of-an-object-to-a-collision-normal
system
2
|
|
|
|
Reply From: |
wowzzers |
I’ve managed to get it working. You just have to zero out the other 2 bases.
Here’s the function:
func align_with_normal(trans : Transform, normal : Vector3):
trans.basis.x = Vector3.ZERO
trans.basis.y = Vector3.ZERO
trans.basis.z = normal.normalized()
return trans
trans for the transform of the mesh instance, normal is for the raycast hit result normal.
But if there’s a better way, please, answer.
You don’t even have to normalize the result normal, I guess.
wowzzers | 2020-02-13 14:21