[SOLVED] Calculating angle between two vector

Hey! I am making a bowling game in which i need to check whether the pins are fallen down or not? I was checking before by getting Eular angles. The problem is Euler angles doesn’t give the same rotation value as in editor.

So i have changed the approach now. Now my question is how can i find angle between both the local and World UP vectors. Both Pictures are attached.
This image has a local vector perspective. While the image below has the World vector perspective changed through inspector.

Just to remind in both the pictures rotation value is not changed just perspective is changed from local to world.

Do you need an exact angle or just to know that it’s not fully upright?

If the latter, you can do a dot product between the entity up vector against world up. If it’s nearly 1, it’s up right, else it has tipped.

I need an exact angle so that i can define specific threshold. But first let me try the dot product and check whether it works for me or not.

As both vectors are normalised, you can use a threshold on the dot product as fully horizontal would be 0.

If you still need to get the angle, you can acos the dot product between two normalised vectors to get the angle.

Hey @yaustar! can you tell me the syntax to find local UP and World UP as i am confused in its syntax?
Till Now, i was normalizing the rotation vector and then taking dot product but it doesn’t seems to work perfectly. I am using the following syntax now.

this.temp = new pc.Vec3(20,0,0).normalize();
let temp3 = this.temp.dot(this.allPins[0].pinPosition.normalize());
var dot = this.entity.up.dot(pc.Vec3.UP);

This would be the dot product between the entity’s up vector and the world up.

1 Like

Thanks alot :slight_smile: