# Limit Object Transformation with API

13 March 2016 14:47
Hi community.

I can control my little robot arm with the keyboard to rotate the arms around.

I do the rotation with the api when the key is pressed, e.g.:
``m_transform.rotate_x_local(m_scenes.get_object_by_name("Robot.A2"),-0.05);``

Im struggeling around with limiting the rotation, so the arms don't move through each other. Any idea?

``rotQuat = m_transform.get_rotation(m_scenes.get_object_by_name("Robot.A2"));quatString = m_quat.str(rotQuat);``

Above i get the quaternion, but don't know how to check this for reaching limits.
13 March 2016 16:38
Hello and welcome to the forum.

We have a very similar example, but it works with bones. Take a look at this demo, please. Limits are defined inside the init_bones_info function, and the actual movement is performed in the move_bone method.

As for me, bones API is more suitable for such tasks, because it can use Blender's bone hierarchy and thus, when the root object moves, all its children are translated accordingly.

14 March 2016 20:13
Thanks for the fast reply.

I adapted your example, but I have a problem with the quaternions.

By pressing a specific key the arm should turn around z-axis for one small amount, so that by holding the key it continuously rotating around z.

How do I calculate a single step only for z -axis based on the TSR of an armature bone?

Right now i try this:
``var rig = m_scenes.get_object_by_name("Armature");	var temptsr = base_tsr;	var qtemp = m_quat.fromValues(base_tsr[4],base_tsr[5],base_tsr[6],base_tsr[7]);	m_quat.rotateZ(qtemp,Math.PI/180, qtemp);	m_tsr.set_quat(qtemp,temptsr);	m_armat.set_bone_tsr_rel(rig, "Bone.Base",temptsr);``

Which leads to this:
15 March 2016 17:57

How do I calculate a single step only for z -axis based on the TSR of an armature bone?
As far as i can see from screenshots you need to rotate your armature object around global vertical axis, which is Y axis in webgl space.
You can try:
```var rig = m_scenes.get_object_by_name("Armature");
var temptsr = base_tsr;
var qtemp = m_quat.fromValues(base_tsr[4],base_tsr[5],base_tsr[6],base_tsr[7]);

// axis to rotate around
var glob_Y = m_util.AXIS_Y;

// global rotation quaternion
var glob_quat = m_quat.create();
m_quat.setAxisAngle(glob_Y, Math.PI/180, glob_quat)

// getting result rotation into qtemp
m_quat.multiply(y_quat, qtemp, qtemp);

m_armat.set_bone_tsr_rel(rig, "Bone.Base",temptsr);
```
Blend4Web Team - developer