- Home /
Change rotation axis for 3D object (robot Joints)
Hello, so I have this script that i found in a package which i am using to control a robot (TFAttachement.cs)
From my terrible programming experience, I suspect that the last two lines make it so that the robot spawns at 0,0,0 and the joints are rotating around this point as well.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Unity.Robotics.ROSTCPConnector
{
public class TFAttachment : MonoBehaviour
{
[SerializeField]
string m_FrameID;
public string FrameID { get => m_FrameID; set => m_FrameID = value; }
[SerializeField]
string m_TFTopic = "/tf";
public string TFTopic { get => m_TFTopic; set => m_TFTopic = value; }
void Start()
{
transform.parent = TFSystem.GetOrCreateInstance().GetTransformObject(m_FrameID, m_TFTopic).transform;
transform.localPosition = Vector3.zero;
transform.localRotation = Quaternion.identity;
}
}
}
The problem is i want to move the robot to be placed at another location than 0.0.0, so I thought to change the last to lines to this :
transform.position = new Vector3(-2,0,0);
transform.rotation = Quaternion.identity;
problem with this one is that when the robot rotates, the joints are rotating and moving relatively to the 0,0,0 point and not spawn, showing the joints flying in space.
I have been trying to find a way to fix the rotation so that is showing correctly, and relative to the new point, but to no end. Any help would be appreciated
Answer by JonnyHilly · Mar 31 at 05:52 PM
make sure you understand the difference between "localPosition" and "Position" you have changed this. perhaps you did not want to do that.
Local position is the position of each node/transform, away from it's direct parent transform in the hierarchy. position.... is its absolute world position in the unity scene / world.
also when are setting an object's parent, you might want to use transform.setParent( parent, mode ) as when you reparent things... the object can move if you don't use the correct mode.