and this is a import
by user 274576156684976128
and this is a import
by user 274576156684976128
but i have a error
by user 274576156684976128
Cannot read properties of undefined (reading ‘setFromAxisAngle’)
by user 274576156684976128
Yes your quaternion (this.rotateQuaternion) is not initialized. You need to call new Quaternion() somewhere otherwise it will be undefined
I recommend to do it in awake
by user 274576156684976128
this how we do rotateTowards in unity
by user 274576156684976128
and this is three.js
by user 274576156684976128
this.model.quaternion.rotateTowards
by user 274576156684976128
I need make new vector and then assign it to the rotation?
by user 274576156684976128
No, you use a quaternion in threejs. three.js docs
But the code sample you sent does not initialize your variable here: rotateQurternion : Quaternion this is how I define it
Instead you need something like this:
rotateQuaternion : Quaternion = new THREE.Quaternion()
then you can use it with this.gameObject.quaternion.rotateTowards(this.rotateQuarternion, 0.2)
Otherwise this is the error you get
Assignment to constant variable.
by user 274576156684976128
give me this error
by user 274576156684976128
rotateQuarternion= new Quaternion();
by user 274576156684976128
There is a important difference between Vector3 and Quaternion in threejs and Unity. In Unity you deal with value types and in threejs these are reference types so you need to initialize / new them before you’re able to use them
like this no error
by user 274576156684976128
I know
by user 274576156684976128
would be helpful if you could send a bigger chunk of your script - makes it easier to help