Player head location

  • I was thinking about how awesome it would be to have a plugin that echoes chat messages to speech bubbles over the players head rather than in the chat window.


    To accomplish this, we need to know the position of a player's face on the screen. if they go offscreen then the value should be the point along the edge of the screen in line with the face.


    I guess additional player methods needed would be something to get the distance between two players so we can determine whether the other person is within "hearing" range.

  • To accomplish this, we need to know the position of a player's face on the screen.

    Not necessarily, if the "balloon" is implemented as 3D text, it just needs to be positioned above the player position, which is well known. and then added as a WorldElement to the world of each player nearby. It would be necessary to rotate it so that it always faces the on-looking player, but this is rather trivial trigonometry.

    I guess additional player methods needed would be something to get the distance between two players so we can determine whether the other person is within "hearing" range.

    Neither. The distance can be easily calculated from the respective player positions, as volume decreases with the square of the distance, it is not even needed to calculate the 'real' distance (which requires an expensive square root): the square of the distance is fine.


    Maybe, the whole may have some performance impact, as distance and rotation angle needs to be recalculated for each pair of players, whenever one of them moves.

  • I enjoyed these chat bubbles when I was on an FTB server long ago, yet miss the fun of it. You would see them when within spawn distance of the chunks, yet when you were too far it wouldn't pop up. I'd be amused to see these on NPCs in the game, as well as player side.


    Well, I'm no expert so I guess I'll leave the deep thoughts to those that have actual skill to script this.....Or even Red51 to give the ability for others to reverse-engineer. It be awesome to have these.

  • Not necessarily, if the "balloon" is implemented as 3D text, it just needs to be positioned above the player position, which is well known. and then added as a WorldElement to the world of each player nearby. It would be necessary to rotate it so that it always faces the on-looking player, but this is rather trivial trigonometry.

    Neither. The distance can be easily calculated from the respective player positions, as volume decreases with the square of the distance, it is not even needed to calculate the 'real' distance (which requires an expensive square root): the square of the distance is fine.
    Maybe, the whole may have some performance impact, as distance and rotation angle needs to be recalculated for each pair of players, whenever one of them moves.


    Interesting .... Thanks for the insight. Something tells me you're already working on this. ;-p

  • Interesting .... Thanks for the insight. Something tells me you're already working on this. ;-p

    Not really, I am busy with completing projects already in progress (not to mention that I am writing this from an on-the-fly Linux CD live, as the main HD of my PC has problems...) but, who knows (who' nose...) ...

  • To accomplish this, we need to know the position of a player's face on the screen

    The head has a fixed offset, so it's not a problem to calculate it from the existing player position. Although this offset may change when the new playermodels are implemented... maybe we will add a "getHeadPosition()" or something like that for reasons of convenience ;)


    I guess additional player methods needed would be something to get the distance between two players so we can determine whether the other person is within "hearing" range.

    As @Miwarre said, you can already calculate the distance between two players. The "getPosition()" method returns a Vector3f, which has built-in methods to get the distance or the squared distance (to avoid the square root, as @Miwarre mentioned). So you could do something like:


  • The head has a fixed offset, so it's not a problem to calculate it from the existing player position. Although this offset may change when the new playermodels are implemented... maybe we will add a "getHeadPosition()" or something like that for reasons of convenience ;)

    Any additional method is surely welcome. But for this specific goal a Player.getHeadPosition() is possibly not so necessary.


    Unless you plan to allow player models to be really HUGE (the size of T-Rex, for instance), but plan to have them all in the range of the size of a human being, placing each "balloon" a fixed amount above the player ground position, for instance 2.5 ÷ 3 m (5 ÷ 6 blocks) would be enough for it to clear the player head top.


    This would also have the added advantage of a constant relationship between player position and balloon position, making easier to see the position relationships.

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!