Set a Player's speed?

What would be the best way to set a Player’s speed? I get the feeling I’ll need to do it in a very abstract way…

This has already been answered in another thread. I can understand that you didn’t find it, though, it is rather convoluted :stuck_out_tongue:

1 Like

From what I see in the post you linked, that simply sets their instantaneous velocity. I’m looking to change their actual speed indefinitely over time. Does this make sense?

A while loop? (A)

I don’t know Java, and I don’t know Sponge that well, but perhaps there is an event you could be listening to? PlayerFlyMovementEvent or PlayerRunEvent or PlayerAscendEvent or some equivalents (these example events are complete pseudo, so don’t expect them to work :stuck_out_tongue: ).

Whenever your player triggers that event, you multiply his instantaneous velocity by some variable until he stops moving again?

This will lead to a lot of checks if many players are /speed-ing at the same time, though. Perhaps somebody who’s better than me at Sponge has a better idea?

EDIT: what if you manipulate potion effects? Apply speed and possibly jump while they’re moving?

So basically you dont know anything about the language, nor the framework, but you are “trying” to answer someone’s quetion. Please do not do this its not helpful at all.

read again what gabizou wrote, you will have to use AttributeData

2 Likes

Please don’t misquote me, I said I didn’t know Sponge that well. Since his question was a direct reply to me, I decided to try to point him in some directions that might work, until someone who knows the language could confirm or point elsewhere; i know from my experience in other languages that going without an answer is much more frustrating than getting a pointer, even if that pointer turns out to not be the correct answer in the end.

I honestly don’t see how suggesting to look through Sponge’s events “isn’t helpful at all”. Worst case scenario: it doesn’t work, but he gets a better understanding of some of the other events that exist in Sponge. On the other hand, being bombastic seldom helps. Especially if you misquote while doing so :smile:

@soccer66 Sorry for pointing you in the wrong direction, but hopefully you learned something, at least ^^,

2 Likes

So I have something along the lines of:

player.offer(p.getOrCreate(VelocityData.class).get().velocity().set(new Vector3d(My Vector Here)));

However, this doesn’t work for some reason, and event if it would, it’s not what I’m looking for. From what I can tell, this is using the AttributeData and DataManipulator @gabizou mentioned (or at least the DataManipulator). I’m looking for the effect speed potions provide, or the Essentials speed command from Bukkit. Thanks :facepunch:

Just to shorten it, you could use:
player.offer(Keys.VELOCITY, new Vector3d(x,y,z))

I also have this issue where the velocity is not actually being set, but it may or may not be related to issue 149

I have a few thoughts on this thread:

  • When you mean a Players speed, I’m going to assume that you’re talking about their walk speed attribute value of which can range from 0 and 2(?). This should be already represented in the Data API either through a manipulator or through a Key. If not, I do believe there is an issue still open on it and I haven’t gotten around to actually writing it.
  • The instantaneous velocity is a little bugged as mentioned by a few people in this thread, I’ve assigned @Aaron1011 to work on fixing it for players as I’m in the midst of refactoring events.

What you should be able to do as soon as the walking speed is available through a key is:

player.offer(Keys.WALK_SPEED, 0.2);

i think it can be also negative, negatigve values inverse player’s movement