Calculating Player Speed to Divide Integer

Discussion in 'Spigot Plugin Development' started by WAS, Apr 23, 2017.

  1. WAS


    I'm... confused.

    So I have been working on a event system. And it's decent. But it has two big problems. The first one is depending on the speed of the player, the blocks traversed will not be accurate. For example. If you jump to fly mode and just fly up, your blocks will be accurate based on just dividing by two because of the frequency PlayerMoveEvent is fired. But if you fall from that height, you will gain speed. So not only is there a variation for player gaining speed, but when he is at max speed the blocks fallen are way out of range. For instance if you risen about 240 something blocks you'll have fallen around 40 something blocks.

    The second issue I am having is occasionally, again because of the frequency of the jump event, sometimes lands are not register because at the same instant (I am guessing) the player wasAirborne is being set to true again. Not sure but what I imagine It might be.

    If any math wizards want to take a peak the source is all up online at GitHub:

    Any suggestions on how to get the main issue figured out, or the secondary issue would be much appreciated
  2. NathanWolf


    I was thinking you'd get some responses by now..

    The only useful suggestion I have is for the first part- if you want to track the falling speed of a player (or just their velocity in general) you need to track the distance they've moved from one block to the next, instead of assuming it with a /2. That is basically trying to calculate a speed assuming you know the approximate speed in the first place.

    If you only care about vertical movement this should be as easy as replacing the places where you're simply adding 1 or 1/2 with adding the difference between the Y values of the previous and current blocks.

    That's probably oversimplifying, but I think is the general idea. It might be better to start with just tracking actual velocity (as a vector) and then basing falling/jumping off of that?
  3. WAS


    Well that's the point, I know the relative speed of a normal jump and fall within 5-10 blocks. It's falling in general where the variable is lost. That's the issue... and the question? Getting the speed, to a integeter, to divide the blocks.

    Not sure what you mean by that? Another variable is the frequency at which the PlayerMoveEvent fires in relation to speed as well.

    Yeah that's my question... :( I don't know where to start. The velocity can't be used against the division, so a velocity is useless unless transformed into an appropriate integer. The question is how to calculate this velocity to an appropriate integer to use.
  4. NathanWolf


    If you want instantaneous velocity in ticks, that is just the distance between from and to in PME (assuming this only fires once per tick per player, which may not actually be true, not sure). If they were at Y=60 and they're now at Y=50, they've moved 10 blocks in one tick. So their falling speed is 10 b/t.

    If you want velocity per second you'd have to also track time between PME's, so if the above example it took 200ms between PME's, they've moved 10 blocks in 200ms, instantaneous velocity would be 50 b/s.

    If you're looking for some sort of measure of average velocity over a time span it gets more complicated. But at this point I feel I'm not fully understanding your question.
  5. WAS


    Maybe you don't understand the question in whole. I don't know where to begin to even approach this. I have dyscalculia and cannot even retain times tables, I literally cannot manipulate numbers in my head or hold on to them. I have a piece of paper in my wallet with my phone number... Like all mathematics I do is based on visual objects in my head. One apple, two apples. It's a retardation. Yes.

    You can talk pretty but unless I see examples to do trial and error, I am not sure what you even mean, or how to formulate it.

    Maybe this question is best for SO.

    Also: getVeolicty would appear useless in your descriptions, is that true? What is the point of it than?