Unity Vector3.angle Equivalent

is there unity Vector3.angle Equivalent in PlayCanvas

No but you can get the dot product of 2 vectors. The dot product is equal to the arccos for the angle (if the vectors are normalized). So to get the angle in degrees you can do something like:

var dot = vecA.dot(vecB);
var angleInRadians = Math.acos(dot);
var angleInDegrees = angleInRadians * pc.math.RAD_TO_DEG;

Usually though you don’t really need the angle in degrees you can solve your problem with less math… Depends on what exactly you’re trying to do…

1 Like

thank you. I just try lookAt to a point with rigidbody torque :). because entity.lookAt not work with rigitbody when rigitbody has a linear force . What will your way to rotate rigidbody character to look at a point? I m experinced developer but not a game developer that much.

Sorry my english :slight_smile:

If you want to rotate an entity with a rigidbody to look somewhere either you’ll do it with adding some amount of torque towards the desired direction or you can create a quaternion that makes the entity look towards the desired target and then call rigidbody.teleport (https://developer.playcanvas.com/en/api/pc.RigidBodyComponent.html#teleport^2).

You could do something like:

entity.lookAt(target);
entity.rigidbody.teleport(entity.getPosition(), entity.getRotation());
1 Like

isn’t it teleport reset all other force applied to rigidbody?
I apply teleport but know chacter not collide with other objects.
project link: https://playcanvas.com/project/491294/overview/shootthemall

I don’t think that teleport resets forces. I think in your code you are actually moving the character using teleport which means that the character will just blindly go wherever you tell it to go, it won’t collide with anything.

You should try using forces to move the character but just control the rotation using teleport, I think that should work, but I’ve never tried it myself.

entity.lookat broke all physic for rigidbody.applyforce. teleport work but it broke collion. So i do physic baset lookat with torque. thank you :).