- Home /
object transform and clamp in local direction
I am moving an object with mouse raycast but the problem i am having is that it collides with other objects, my object have 4 raycast from its center in angles(forward,backward,right ,left) and those raycast collides with walls and then i get the lowest ranged raycast and rotates the object according to it, what i want to do is that at certain range of lowest ranged raycast the object does not go in backward direction even i forced it to go , it should only go forward ,right and left.
lines of code for object transform: {
currentPlaceableObject.transform.position = hitInfo.point; //hitinfo is mouse position
currentPlaceableObject.transform.rotation=Quaternion.FromToRotation(currentPlaceableObject.transform.up, hitInfo.normal) * currentPlaceableObject.transform.rotation;
} Rotation on the lowest ranged raycast is :
if(raycastHit.distance<2.0f)
{
currentPlaceableObject.transform.rotation =
Quaternion.FromToRotation(Vector3.forward,raycastHit.normal);
currentPlaceableObject.transform.rotation = Quaternion.Euler(0.0f,
currentPlaceableObject.transform.eulerAngles.y, 0.0f);
}
i can share my script but its quite messy, Thank you
Your answer
Follow this Question
Related Questions
Clamp X position of object 1 Answer
How I can Converting a Direction Vector to Quaternion rotation? 1 Answer
transform.position = new Vector 3 NOT moving to correct position? 1 Answer
move a transform to a vector 3? 2 Answers
Difference Between Transform.TransformVector and Transform.TransformPoint 1 Answer