- Home /
Question by
jack_ashton · Nov 27, 2021 at 07:46 PM ·
movementsnapping
How to snap an object to an axis in 3D?
I have a script that lets player move Rigidbodies in my game with a mouse, and I want some objects to snap to some guides when they are near. So the object will move freely when no guide is near, but when it is, then it will move only along the guide. Basically this line is my movement logic for now. When a raycast hits the guide, it affects the movement of an object.
transform.position + Vector3.Scale(guide.transform.position - hit.point, guide.transform.up)
Then I linear interpolate this value to get a smooth movement. It kinda works, but if the guide is only rotated straight and also the movement can be inversed. Any ideas on how to implement this?
Comment