If you check out the demo, you’ll see that this works perfectly with a demo cube mesh.
But when I replace the cube mesh with an imported mesh from a .GLB file, movement becomes, strange. This code is commented out, so you can easily swap in/out and see the difference.
It’s almost as if the playerMesh object is not readable or something.
What am I doing wrong here?
https://www.babylonjs-playground.com/#Y2XX5A
Your playerMesh.rotation is never set for the shark.
(Maybe parent it to a transformNode)
1 Like
Thanks so much!
I updated the demo here:
https://www.babylonjs-playground.com/#Y2XX5A#2
I had to swap forward and backward for it to work. And also rotate the transformNode AND playerMesh. I don’t really understand why. But it works!
If there is a more elegant way to use the transformNode, or maybe a way that makes more sense, please show me
All help appreciated!
I’ve been using something more like
var x=playerSpeed*CoT.forward.x;
var z=playerSpeed*CoT.forward.z;
In place of
var x=playerSpeed*parseFloat(Math.sin(CoT.rotation.y));
var z=playerSpeed*parseFloat(Math.cos(CoT.rotation.y));
Since the info is there. TransformNode - Babylon.js Documentation
=)
1 Like
Ahhh, that’s fantastic. I was confused with my own “forwards” variable that I set for a moment, but “forward” is actually a property of the transformNode, and it takes care of that pesky trigonometry! I knew there had to be an easy way to do this. Thanks 
I improved the third-person shark adventure here:
https://www.babylonjs-playground.com/#Y2XX5A#3
1 Like