β˜‘ Problem with localRotation causing skewing and not rotation

Hi,

I have an entity with a box model which when I am doing a local rotation it is skewing the model rather than rotating it.

Project can be found at

https://playcanvas.com/editor/scene/454060

basically its a keyboard with keys. The keys are just collision objects but they have a child which is the model.

I set the rotation of the model in note.js like this:

this.keymodel = this.entity.children[0];
this.keymodel.rotateLocal(-10,0,0);

but instead it rotating the model skews like its being pushed over.

where did I go wrong?

Shouldn’t you be rotating the parent so this.entity.rotateLocal instead?
And since there is a rigidbody on there you might want to use this.entity.rigidbody.applyTorque(-this.torque, 0, 0);

but I’m not sure if I’m getting the setup correctly

Parents of those entities are scaled with different values per axes, this leads to local coordinates of children to be stretched, that is why you see this skewing.
Or rotate parent, or apply scale to child, not parent of it.

Hi,
I cannot rotate the parent because the collision box must remain where it is while the model rotates. Is there a way for me to keep the parent in the same position and same size while rotating the child?

You could unparent the Box and just have them on the same hierarchy level or you could try to rotate in world space rather then local space .

Hi,
I tried the rotation in world space and it has the same result
Separating them from the parent seems extreme because I need to maintain the link (which I could do through naming I guess) but it might be the only solution.

I told you the solution - do not scale parent, scale the child that you are rotating. Or have one parent with two children.
And in fact parent that has collision has no need of scale what so ever. It has no model to it, so scale is irrelevant on it. Scale child, not parent.

Hi Max,
Confused by your comment, if a collision has no need of scale then how do you create trigger volumes of a particular shape?

I need to scale the collision box so that it has the same dimensions as the model. Basically I need the collision box to be a rectangle with the same size as the model but it must stay stationary while the model moves.

The collision box is basically a trigger for a particular model but the collision box needs to have a particular position and size.

I can work around it, it’s not a big problem. You explained why the rotation causes a skew and that’s all I really need.

Scale does not affect collision/trigger shape dimensions.
Have you tried changing scale and observing the collision shape? It stays the same.

So please, try as I’ve suggested: do not scale parent (make it to 1,1,1 back) and scale child. halfExtents - is what defines size to the collision/trigger shape.

Experimentation - is a key of learning and achievement as a developer.

1 Like

oh, I think I understand what you mean now. I will give that a try. Thank you max.

1 Like

you were absolutely right , perfect, thank you.

1 Like