W1lly Posted August 12, 2015 Share Posted August 12, 2015 Hello Babyloniens, I am currently working on latency-sensitive events such as shooting at another player in the context of a real-time multiplayer game. I would like to be able to check the past positions and animation states of my players. It would be very handy if I could access my scene object as it was a few frames ago. This way I wouldn't have to reconstruct the scene each time I need to access my player's past positions, and I could directly cast rays on the scene to determine the aiming of the player who is shooting. To do that, I was thinking that the best solution would be to keep an history of the past rendered frames.Is there a way of doing that in babylon.js ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 12, 2015 Share Posted August 12, 2015 Not really but you can register a function on scene.afterRender and save meshes positions to an array for instance Quote Link to comment Share on other sites More sharing options...
W1lly Posted August 13, 2015 Author Share Posted August 13, 2015 Ok I see, thank you for your answer Deltakosh One more question though: how could I save the exact bones position/rotation for a given frame? Also I read that making instances of a mesh would result in all instances sharing the same armature, is that correct? If so, is there a way of "copying" the armature rather than creating a new armature manually? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 13, 2015 Share Posted August 13, 2015 You can clone the armature but it could be really expensive. As I understand your ask you just want players positions right? so why do you want to save armature as well? Quote Link to comment Share on other sites More sharing options...
W1lly Posted August 13, 2015 Author Share Posted August 13, 2015 Actually, ideally I would also want to save the bones positions. When a player shoot at another player, depending if the targeted player is running/jumping or whatever, the hitboxes won't be in the same position since they follow the armature transformations, which depends on the animation running at this moment. I seem to have solved this, not sure if this is the best solution but still, if someone is interested to know how I solved this: - On each rendering frame I just make a clone of my player's mesh and modify its position to reflect the player's position. I also clone the skeleton of the mesh - Then, knowing the current frame of the animation being played, I make a scene.beginAnimation between the frame and frame+1, at a speed of 0 (so I end up with the cloned mesh being stuck in the position of the current frame of animation) - I store this clone in an array with the length fixed to the number of past positions I want to save, lets say 10 for instance (so there is a mechanism that makes sure the array is always of length 10, deleting the index 0 and adding at the end when the array is full). I also store the exact timestamp of the rendering frame. - Know, when casting a ray I can easily choose the appropriate clone by modifying the predicate of the function. Not sure if I am very clear here...Anyway, I am still open to suggestions Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 14, 2015 Share Posted August 14, 2015 Glad that you found a way 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.