ozRocker Posted May 19, 2016 Share Posted May 19, 2016 I'm using babylon 2.4 here. I've providing position vectors to the Vector3.lerp function. The result seems to be a string concatenation instead of arithmetic addition. Below I'm just showing x, z coordinates because y is always constant from: 2.000, 0.000 to: 2.400, 0.000 lerp percentage: 0.33589999999996506 lerped position: 2.0000.134359999999986, 0.0000 lerp percentage: 0.9552999999999884 lerped position: 2.0000.38211999999999524, 0.0000 so this is going from (2.0, 0.0) to (2.4, 0.0) The 1st resulting lerp should be 2.134359999999986 but instead its 2.0000.134359999999986 Quote Link to comment Share on other sites More sharing options...
adam Posted May 19, 2016 Share Posted May 19, 2016 It's working correctly here: http://www.babylonjs-playground.com/#U7ZR7#1 If you aren't using Typescript, make sure you aren't somehow setting your Vector3 with strings. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted May 19, 2016 Author Share Posted May 19, 2016 yep, that was it. The mesh position values were treated as strings because they were set from a JSON record. I had to cast them to numbers. The weird thing is that the scene renderer was treating that position vector as numbers and moving my avatar along normally, which is why I didn't pick this up before. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Dal Posted May 28, 2016 Share Posted May 28, 2016 On 5/19/2016 at 3:48 PM, ozRocker said: yep, that was it. The mesh position values were treated as strings because they were set from a JSON record. I had to cast them to numbers. The weird thing is that the scene renderer was treating that position vector as numbers and moving my avatar along normally, which is why I didn't pick this up before. This is exactly why you should learn Typescript I'd really recommend pushing through the initial PITA of getting started. If you'd written that in Typescript you'd have a red line under it in your IDE. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted May 29, 2016 Author Share Posted May 29, 2016 2 hours ago, Dal said: This is exactly why you should learn Typescript I'd really recommend pushing through the initial PITA of getting started. If you'd written that in Typescript you'd have a red line under it in your IDE. I am using Typescript. My whole project is in Visual Studio. I didn't see any error or any red line. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted May 29, 2016 Author Share Posted May 29, 2016 My code is kinda like this in Typescript: var vector: BABYLON.Vector3; var JSONstring: string; var instruction = JSON.parse(JSONstring); var message = instruction.message; vector = new BABYLON.Vector3(message.player.position.x, message.player.position.y, message.player.position.z); I'm dealing with a JSON string that gets parsed into a combination of objects and strings so I can't give strict types for them. Because of that I'm passing untyped data to the Vector3 constructor. No red-line or error. Also, the code runs even with the strings in there. Babylon.js has no problem with it. Its only when I do standard javascript arithmetic is when the problem arises. Quote Link to comment Share on other sites More sharing options...
Dal Posted May 29, 2016 Share Posted May 29, 2016 21 hours ago, ozRocker said: My code is kinda like this in Typescript: var vector: BABYLON.Vector3; var JSONstring: string; var instruction = JSON.parse(JSONstring); var message = instruction.message; vector = new BABYLON.Vector3(message.player.position.x, message.player.position.y, message.player.position.z); I'm dealing with a JSON string that gets parsed into a combination of objects and strings so I can't give strict types for them. Because of that I'm passing untyped data to the Vector3 constructor. No red-line or error. Also, the code runs even with the strings in there. Babylon.js has no problem with it. Its only when I do standard javascript arithmetic is when the problem arises. class Player { position:Vector3 = Vector3.Zero(); } var message = instruction.message; var player:Player = <Player>message.player; vector = new BABYLON.Vector3(player.position.x, player.position.y, player.position.z); That probably won't work as it is but something on those kind of lines would avoid passing untyped data around. If message.player is the right shape it should fit. ozRocker 1 Quote Link to comment Share on other sites More sharing options...
ben_a_adams Posted June 12, 2016 Share Posted June 12, 2016 You can cast them with `+` as follows vector = new BABYLON.Vector3( +message.player.position.x, +message.player.position.y, +message.player.position.z); jerome 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.