Hello Everyone 
I’m learning with this Robot Toy… But I can’t make the Arm Base rotate in Axis Y… I didn’t have problems with the other parts…I have several days trying to fix it, but I can’t…
I can’t make it rotate in axis “Y” Any help please!
Here it is the file and you can see the image.
Thanks in advance
Keyboard:
Base Arm “R” “Y”
Arm 1 “A” “D”
Arm 2 “Q” “E”
Hand “Z” “C”
470240–16513–$Robot Toy.rar (238 KB)
Any chance you could post some code, just for those who don’t get around to downloading your project (or whatever the attachment is)?
What you describe should be a simple matter of proper object parenting and applying appropriate rotations in local space; if it’s not working, I’m guessing it’s simply because you’re handling the rotations in the wrong way. If we can see the scripts that manage the rotation, I imagine someone might be able to spot the problem even without seeing the project itself.
(Also, here is a link to your UA post on the same subject.)
Hello Jesse!
Here it is the screenshot of the hierarchy of the Arm with the parenting. Each segments is rotating in Local Axis.
And here are the scripts for each segment.
Thanks
Base Arm Script:
var gunSpeedNeg: int = -40;
var gunSpeedPos: int = 40;
function Update () {
if(Input.GetKey("r")){
transform.Rotate(Vector3.right* gunSpeedNeg* Time.deltaTime);
}
if(Input.GetKey("y")){
transform.Rotate(Vector3.right* gunSpeedPos* Time.deltaTime);
}
}
Arm 1 Script:
var gunSpeed : float = 40;
private var rotation : Quaternion = Quaternion.identity;
private var left : Quaternion = Quaternion.AngleAxis(-150, Vector3.up);
private var right : Quaternion = Quaternion.AngleAxis(30, Vector3.up);
function Start ()
{
// This piece of code will allow you to remember the origin.
rotation = transform.rotation;
left = rotation * left;
right = rotation * right;
}
function Update ()
{
var speed = gunSpeed * Time.deltaTime;
if(Input.GetKey("a"))
{
rotation = Quaternion.RotateTowards(rotation, left, speed);
}
if(Input.GetKey("d"))
{
rotation = Quaternion.RotateTowards(rotation, right, speed);
}
transform.rotation = rotation;
}
Arm 2 Script:
var gunSpeed : float = 40;
private var rotation : Quaternion = Quaternion.identity;
private var left : Quaternion = Quaternion.AngleAxis(-15, Vector3.up);
private var right : Quaternion = Quaternion.AngleAxis(90, Vector3.up);
function Start ()
{
// This piece of code will allow you to remember the origin.
rotation = transform.rotation;
left = rotation * left;
right = rotation * right;
}
function Update ()
{
var speed = gunSpeed * Time.deltaTime;
if(Input.GetKey("q"))
{
rotation = Quaternion.RotateTowards(rotation, left, speed);
}
if(Input.GetKey("e"))
{
rotation = Quaternion.RotateTowards(rotation, right, speed);
}
transform.rotation = rotation;
}
Hand Script
var gunSpeed : float = 40;
private var rotation : Quaternion = Quaternion.identity;
private var left : Quaternion = Quaternion.AngleAxis(-25, Vector3.up);
private var right : Quaternion = Quaternion.AngleAxis(80, Vector3.up);
function Start ()
{
// This piece of code will allow you to remember the origin.
rotation = transform.rotation;
left = rotation * left;
right = rotation * right;
}
function Update ()
{
var speed = gunSpeed * Time.deltaTime;
if(Input.GetKey("z"))
{
rotation = Quaternion.RotateTowards(rotation, left, speed);
}
if(Input.GetKey("c"))
{
rotation = Quaternion.RotateTowards(rotation, right, speed);
}
transform.rotation = rotation;
}
Can you repost your code using ‘code’ tags and proper indentation? (Assuming you haven’t already figured it out, that is.)
Okay Jesse no problem, thanks
Paco, you are using the same key to move two different pieces of the robot.
That is, the E key is used for Arm2 and Hand.
Thanks Juan,
That was only a mistake in the text, I’m going to try to change the Axis in 3D Max and re-import the model to Unity
Hello,
I fixed the rotation in the correct Axis, but the arm extension rotates keeping the same orientation don’t change (always see to the same direction).
(The Base’s Arm rotates well, but the Arm as a “children” rotates keeping the same orientation)
Please take a look to the image.
Here it is the Script I’m using.
var gunSpeedNeg: int = -40;
var gunSpeedPos: int = 40;
function Update () {
if(Input.GetKey("r")){
transform.Rotate(Vector3.right* gunSpeedNeg* Time.deltaTime);
}
if(Input.GetKey("y")){
transform.Rotate(Vector3.right* gunSpeedPos* Time.deltaTime);
}
}
Any advice is welcome.