Posted January 18, 20169 yr How could I get the player movement speed in my mod in km/h. I want to display it in a GUI in the bottom right-hand corner (which I know how to do). Any ideas?
February 2, 20169 yr If you still are thinking about this, then I would suggest you store players position in variable then on specifid tick you calculate the distance the player traveled since the last "readout". lets say the tick is every second then this pseudo code should be right. //calculate distance since last reading diffx = player.x - prev_posx diffy = player.y - prev_posy diffz = player.z - prev_posz //calculate overall distance distance = sqrt( diffx + diffy + diffz) //calculate speed // speed = distance * 60 *60 /1000 speed_in_km_h = distance*3,6 // store player position for next time prev_posx = player.x prev_posy = player.y prev_posz = player.z Not all things in the world are red, there are round objects too!
February 5, 20169 yr Another way to get the distance (in a perhaps more cleaner way) could be like this: Vec3 lastPosVec = new Vec3(prev_posx, prev_posy, prev_posz); Vec3 currentPosVec = new Vec3(player.x, player.y, player.z); // Euclidean distance between your last and current position. double distanceTraveled = lastPosVec.distanceTo(currentPosVec); As for handling the gui, I am afraid I cannot be of any help there as I have no experience in that. If you haven't so far, you should perhaps read this: http://www.minecraftforge.net/wiki/Gui_Overlay I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java. Follow me on GitHub: https://github.com/yooksi Contact me on Twitter: https://twitter.com/yooksi Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/
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.