Jump to content

Help rotating part around it's attachment point


raath

Recommended Posts

I'm trying to write a plugin that I can attach to spotlights to enable them to be redirected in EVA.

I've looked on a whole bunch of forums but I can't seem to be able to make it go.

This is the closest I've been able to get it to do what I'd like except that it rotates it around the center of the part not the attachment point, and it seems to pivot on the z axis when I only want to pitch on the X.


private void panUp ()
{
direction += 20;
update = true;
}

private void panDown ()
{

direction -= 20;
update = true;
}

public void LateUpdate ()
{
if (update == true) {
//part.transform.Find("model").Rotate(direction,0,0);
var target = Quaternion.Euler (direction, 0, 0);
// Dampen towards the target rotation
part.transform.Find ("model").rotation = Quaternion.Slerp (part.transform.Find ("model").rotation, target,
Time.deltaTime * smooth);
update = false;
}
}

Where am I going wrong?

Link to comment
Share on other sites

That approach assumes it's rotated 0° around the Y and Z axes, you need to use the current rotation for Y and Z when creating your target (transform.localEulerAngles IIRC).

Also, you need to be using localRotation rather than rotation. The latter is positioning in world space so the axes could be pointing in any direction.

As for rotating around the attachment point. That requires movement as well as rotation so just setting the rotation isn't enough, you'd need to use something like transform.RotateAround. I'm not sure whether the attach information is stored in Part though.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...