Alex10 Posted November 26, 2014 Share Posted November 26, 2014 I want to scope after clicking the mouse flew in the direction of movement of the camera, thus emulated shot.Possible example on three.js: http://pauluskp.com/cannotMy attempt to do so at Babylon: http://www.babylonjs-playground.com/#VWXHP#1 Here is the basic code, then I created a sphere when clicked, and then later inscene.registerBeforeRenderthe set coordinates camera adding a constant but probably incorrectly specified coordinates.window.addEventListener("click", function (e) { var bullet = new BABYLON.Mesh.CreateSphere('bullet', 3, 0.3, scene); var pos = camera.position; bullet.position = new BABYLON.Vector3( pos.x, pos.y, pos.z); bullet.material = new BABYLON.StandardMaterial('texture1', scene); bullet.material.diffuseColor = new BABYLON.Color3(3, 2, 0); var alpha = 0; scene.registerBeforeRender(function () { bullet.position = new BABYLON.Vector3( alpha*pos.x, alpha*pos.y, alpha*pos.z ); alpha += 0.01; }); Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 26, 2014 Share Posted November 26, 2014 you want the bullet to start from the camera to the box right? Quote Link to comment Share on other sites More sharing options...
Alex10 Posted November 27, 2014 Author Share Posted November 27, 2014 I want that bullet launched from the center of the screen well, or from behind and flew in the direction of movement. And now I do not understand why a bullet in the center of the scene appears. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 27, 2014 Share Posted November 27, 2014 Here is it:http://www.babylonjs-playground.com/#VWXHP#3 Quote Link to comment Share on other sites More sharing options...
Alex10 Posted November 28, 2014 Author Share Posted November 28, 2014 Thank you very much this is what I wanted to need.I myself would probably not done. Quote Link to comment Share on other sites More sharing options...
Alex10 Posted December 8, 2014 Author Share Posted December 8, 2014 I have another question. I'm trying to make a game for multiplayers on websocket and I have a problem with the motion vector bullets still appeared.1) When clicked I call a function selfBullet from class bullet and sent to the server the camera position and the player id.window.addEventListener("click", function() { var bul = new Bullet(); bul.selfBullet(); ws.send( JSON.stringify( { 'e':'shoot', 'id':player.id, 'pos':camera.position } )});2) Server for all other players return these values and calls function remoteBullet from class bulletws.onmessage = function(event){ var bullet = new Bullet(); bullet.remoteBullet(msg.id, msg.pos );}3) And then there is a problem. in function this.selfBullet in a global variable is assigned to the direction trueDirection = direction;but there is a problem for all players bullet flies in the opposite direction from the direction stelby and how to modify the direction I do not have experiencevar trueDirection;function Bullet(){ var bullet = new BABYLON.Mesh.CreateSphere('bullet', 3, 0.3, scene); bullet.material = new BABYLON.StandardMaterial('texture1', scene); bullet.material.diffuseColor = new BABYLON.Color3(3, 2, 0); this.selfBullet = function(){ var startPos = camera.position; bullet.position = new BABYLON.Vector3(startPos.x, startPos.y, startPos.z); var invView = new BABYLON.Matrix(); camera.getViewMatrix().invertToRef(invView); var direction = BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(0, 0, 1), invView); direction.normalize(); trueDirection = direction; scene.registerBeforeRender(function () { bullet.position.addInPlace(direction); }); }; this.remoteBullet = function(player, pos){ bullet.position = new BABYLON.Vector3(pos.x, pos.y, pos.z); scene.registerBeforeRender(function () { bullet.position.addInPlace(trueDirection); }); }; }}example http://pauluskp.com/babylon video The video shows that when a player shoots the right then the left overlooking pine shoots in the opposite http://www.youtube.com/embed/gdzcIUvxst0 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.