How do you rotate about the end of an object with scripting?
The pivot point is the point at which the object rotates.
A crude but super easy way of doing this is create another object and make your object a child of that object. ( ie drag and drop your object onto top of the new object). Then place your object so the point you want want to rotate at is at the center of the parent object.
Rotate the parent object and your object will then rotate where you want it to. You can programitcally modify the child object “My Oject” position within the parent using a transform to alter where the pivot point is.
So in this diagram it shows that your object you put under a holder called “Parent”. Thats just an empty object. You’ve offset the location of “My Object” by -1 as highlighted in Red. So now the pivot point will be where the black circle is instead of where the blue circle is.
Now when you rotate the Parent it will rotate your “My Object” around the pivot point.
Hope this helps.
Now the more programatic way of rotating the object is to use:
function RotateAround (point : Vector3, axis : Vector3, angle : float) : void
Where you define the Axis to do the rotation.
What makes this a little bit more complicated is that the Axis is a world co-ordinate. So to work out the axis you need to find the position of that location you want to rotate around in world co-ordinates.
You can define the object in local space so that is origin is at the end.
You could also make this object a child of another object located where its end point (the point you want to rotate about) is, and then rotate its parent to control its orientation.
Another way to do this is if you want the model to rotate around a point that is not the same as its center point in local space. To do so you need to have a “bone” or tagged vert in your model located in local space where you want the rotation to be relative to. Store off the current location of this point in world space, then rotate the model normally around its local origin, which in your case will NOT be the endpoint. Lastly, reposition the model by translating it an amount defined by oldSavedWorldSpacePositionOfTag - newWorldSpacePositionOfTag. This has the effect of making it seem as though the model rotated around the tagged position in local space. The rotation + translation + position inquiries can all be done via script.
Here is one discussion that gives some more info: