- Home /
How to modify the value of an axis without touching to the others ?
Hi,
I'd like to animate the Robot Arm that comes with The Labo project when I press some key. The problem is that I can't figure how to move the arm part correctly, the body turn well but the arm doesn't follow the movement when I try do move it.
Here is the code: enter code herevoid Start () {
body = GameObject.Find("prop_robotArm_body_001");
arm =GameObject.Find("prop_robotArm_arm_001");
}
// Update is called once per frame
void Update () {
if(Input.GetAxis("Horizontal")<-.1){
Quaternion targetAngle=Quaternion.Euler (new Vector3(0f,0f,0f));
body.transform.rotation = Quaternion.Lerp(body.transform.rotation,targetAngle,Time.deltaTime*rotatingSpeed);
}
else if(Input.GetAxis("Horizontal")>.1)
{
Quaternion targetAngle=Quaternion.Euler (new Vector3(0f,180f,0f));
body.transform.rotation = Quaternion.Lerp(body.transform.rotation,targetAngle,Time.deltaTime*rotatingSpeed);
}
if(Input.GetAxis("Vertical")<-.1){
Quaternion targetAngle=Quaternion.Euler (new Vector3(0f,0f,-30f));
arm.transform.rotation = Quaternion.Lerp( arm.transform.rotation,targetAngle,Time.deltaTime*rotatingSpeed);
}
else if(Input.GetAxis("Vertical")>.1)
{
Quaternion targetAngle=Quaternion.Euler (new Vector3(0f,0f,30f));
arm.transform.rotation = Quaternion.Lerp( arm.transform.rotation,targetAngle,Time.deltaTime*rotatingSpeed);
}
}
and the result for now :
Answer by robertbu · May 17, 2013 at 02:39 PM
I'm assuming you want the arm to have relative rotation to the body, and that all these parts share a parent/child relationship. My first suggestion is to use Transform.localRotation rather than Transform.rotation.
Your answer
Follow this Question
Related Questions
How can I rotate a vector direction around an arbitrary axis? 0 Answers
How can I fix the local axis of pivots from a purchased asset? 1 Answer
Maintain direction regardless of orientation (2) 1 Answer
different axis for different objects? 1 Answer
Problem with rotating two axes independently, simultaneously 3 Answers