danksch Posted August 13, 2017 Share Posted August 13, 2017 Hi guys, I'm trying to make 2D-shapes / 2D-sprites in my Canvas2D (ScreenSpaceCanvas) follow some sprites which are placed in my 3d world. For this, I'm using the BABYLON.Vector3.Project function as followed: Quote BABYLON.Vector3.Project(space.position, BABYLON.Matrix.Identity(), scene.getTransformMatrix(), scene.activeCamera.viewport) However, this is the result: Quote Vector3 {x: NaN, y: NaN, z: NaN} I've checked each of the arguments and they all contain valid values at the time of being called. I've also stumbled across this topic, which uses another 4th argument in the call, but I've had no luck trying it with that one either. Any ideas? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
danksch Posted August 13, 2017 Author Share Posted August 13, 2017 For whatever reason, it works now. I can't say why; I changed a couple of things in between and lost track of the things I've altered; been coding for too long non-stop now. I'm accessing the viewport via scene.activeCamera.viewport, which results in screen coordinates between 0 and 1. To get pixel values in order to place my Text2D or Shape2Ds, I do Quote mytext2D.x = canvas2D.width * projectVec.x; mytext2D.y = canvas2D.height - canvas2D.height * projectVec.y; for anyone who's interested. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.