Jump to content

FreeCamera, direction of movement of the mesh


Recommended Posts

I do play on websocket and I have a problem with the task motion bullet after the server response.

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, 'dir':camera.cameraDirection } )});

2) Server for all other players return these values and calls function remoteBullet from class bullet

ws.onmessage = function(event){   var bullet = new Bullet();   bullet.remoteBullet(msg.id, msg.pos );}

3) And then there is a problem. in registerBeforeRender added to the motion vector bullets constant but it looks pretty chaotic.

this.remoteBullet = function(player, pos, dir){    var ctr = 0;    bullet.position = new BABYLON.Vector3(pos.x, pos.y, pos.z);    scene.registerBeforeRender(function () {        bullet.position = new BABYLON.Vector3(dir.x*ctr, dir.y*ctr, dir.z*ctr);        ctr += 1;    });};

How to get the right direction to draw the bullet movement after the server's response?


example http://pauluskp.com/babylon

Link to comment
Share on other sites

are you sure that your Vector3 return 'float' ?. but I do not know if it'll solve your problem.
scene.registerBeforeRender(function () {    bullet.position = new BABYLON.Vector3(parseFloat(dir.x*ctr), parseFloat(dir.y*ctr), parseFloat(dir.z*ctr));    ctr += 1.0;});

When I test your link, I see no problem.


Link to comment
Share on other sites

The problem is that the second player who shot sphere does not see how it flies sphere

For some reason, the scope of the center of the screen is moving in the wrong direction


Correctly only when shooting in the first person in function this.selfBullet

Link to comment
Share on other sites

I feel that there is a problem with the placement of cameras for player 1 and player 2. something does not seem logical to me when comparing the 2 scene.


left the track player a green box and red box close to him.
the player has the right to see a red box and green box but close too, that gold should be away This player there because it is close to the other if one compares the distance of each player.
A player should have the boxes near him and the other away.
Sorry for my bad english, but I think that there is something not coherent with your network.
Link to comment
Share on other sites

I found a mistake already. I made a mistake by passing "camera.сameraDirection" because for example the camera moves back and forth bullet, so the motion looked very wrong.

I will try to convey direction of the shot using "pickInfo".

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...