Solved Normal movement speed underwater

Discussion in 'Plugin Development' started by YoFuzzy3, Jan 18, 2013.

Not open for further replies.
1. Offline

YoFuzzy3

Are there any reliable ways of doing this? If so please point me in the right direction.

#1
2. Offline

SirLittlemonster7

Well, you could do a player move event then check if there "in water" then set there vilocity.

3. Offline

YoFuzzy3

What velocity would I set the player to though?

#3
4. Offline

SirLittlemonster7

Set it to what you feel is the right speed

5. Offline

YoFuzzy3
Just keep modifying the velocity you add to the player until it feels normal, this is one of those things that unless someone has done it before you'll just have to figure out for yourself .

#5
6. Offline

YoFuzzy3

I've never done anything with Vectors before, could you explain how they work?

#6
7. Offline

YoFuzzy3
Sure. A vector quantity represents both magnitude (in this case speed) and direction. So to modify a players movement in minecraft you need to edit his velocity, which is represented by a vector object.

Here is some example code. In your case you probably want to perform a check to see if the player is underwater and then edit his velocity.

Code:java
` Vector velocity = p.getVelocity();int xmod = 0, ymod = 1, zmod = 0;velocity.add(new Vector(xmod, ymod, zmod));//you can add or multiplyvelocity.multiply(2); //Probably what you want to usep.setVelocity(velocity); `

#7
8. Offline

YoFuzzy3

They both cause the player to have no control over their direction. For example if I change the y axis they'll just get shot up.

#8
9. Offline

YoFuzzy3
The code I gave you was just an example. Try setting their y velocity component to 0. Maybe that will stop them falling. But the issue of having no control is almost inherently linked to what you are trying to achieve in a way. As you can't detect key presses using the default Bukkit api.

#9
10. Offline

YoFuzzy3

I've tried many different velocities, it's always uncontrollable. I guess I can't achieve what I'm after using the Bukkit API.

#10
11. Offline

YoFuzzy3
Unfortunately I don't think so. Unless anyone can shed some insight.

#11
12. Offline

chasechocolate

player.setVelocity(new Vector(player.getLocation().getDirection().multiply(2)));? Completely writing this from scratch, so I have no idea if it will even work.

13. Offline

chasechocolate
Ah yes I remember you can do that and it just takes them where the player is looking.

YoFuzzy3
That might be a viable solution?

#13
14. Offline

YoFuzzy3

I got the following code to give me a pretty good result.
Code:java
`Vector velocity = new Vector();velocity = player.getLocation().getDirection().multiply(1.01);player.setVelocity(velocity);`

Although because of the limitation I think I'll make it something the player can activate/deactivate. Thanks for the help!

Edit: It seems like no matter what I set multiply to it always gives the same speed.

#14