Copy rotation of an entity

I want to copy the roation around the y (up) axis of an object (spawnpoint) that is facing the camera and assign this rotation to an other object (myEntity).
I set the rotation of the toolSpawnpoint to camera rotation like this:
And getting the y rotation of the spawnpoint with this:
I assign this rotation to another object myEntity:
myEntity.setEulerAngles(0.0, spawnpoint.getEulerAngles().y, 0.0);

My problem now is, that I get an angle between -90 and +90 degree. The rotation angle increases till +90° and then decreases until it reaces -90° again. So for 180° my rotation is correct and after this first 180° myEntity starts to rotate in the opposite direction for the next 180°.
Why is this happening and how can I fix it? I dont’t get that at the moment.

Hello Patrick and PlayCanvas friends!
I’m facing the same challenge here. Any tips?

Are you trying to do the same thing as the original poster? Or do you have a different situation?

Hi Yaustar! I’m trying to connect a raycast script to the look-camera script. This bit of code should get the rotation of the picked object and rotates the camera accordingly:

this.cameraEntity.script.lookCamera.targetEy = pickedEntity.getEulerAngles().y;

When I expect to get a 180 degress rotation, the script gets 0.7

Not sure exactly what your intention is but it sounds like using the entity.lookAt function would be a better fit here.

An entity’s rotation can be represented in multiple different combinations of eular angles. The engine doesn’t store the rotation of an entity as eular angles but rather in a transformation matrix and the eular angles are calculated hence not getting the expected value on a single axis. The values on the other two axes also matter, even for simple rotation around the Y axis.

Great, thank you, Yaustar! Sorry if I wasn’t very clear. Next time I’ll prepare a clean scene with just the issue.
lookAt sounds great. Had not tried that yet. Will do. :smile:

Hi @yaustar, I made a clean scene with just the issue:

What should happen:
When the user clicks on a panel:
Working: 1) picker-raycast.js animates the camera position to pickedEntity child position, just in front of the pickedEntity.
Working: 2) picker-raycast.js sends zero vertical rotation to camera-look.js as Ex.
PROBLEM: 3) picker-raycast.js sends pickedEntity rotation to camera-look.js as Ey.

So I could manage to get the camera moving to the desired position, rotating up or down, but could not get the camera to animate its rotation towards the panels.

The main problem is that the camera-look.js is controlling the camera rotation. There are a number of ways to handle this and I’m going to give you the most direct route which doesn’t give you a smooth transition of rotation. It will just ‘snap’ to the correct rotation.

As the camera and target entities are all at the same height and we are planning on looking at them straight on, it does make this a lot easier.

You had the right idea on changing the targetEX/Y on the camera look script.

I’ve made a fork of the project with the extra code in picker raycast script:

There are still a few issues but that should get you going.

1 Like

Great! Thanks a lot, @yaustar !
I’ll look into the code and try to lerp the values in the look-camera update loop.
But the way you made it work is already fine to be used as is :slight_smile: Way to go!