Slamming into walls - getting movement direction?

Discussion in 'Plugin Development' started by Chinwe, Feb 25, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Chinwe

    I've been looking around for a while and can't seem to find any way of getting the direction that the player is moving in, not just p.getLocation().getDirection(). How could I get this?

    What I'm trying to do is to listen to PlayerMoveEvent and check the location where the player is going to hit is a block (not air) and then damage them depending on their speed - slamming into walls :>

    The way Im trying to do this is waiting until they hit a wall (using the above method) and then getting their speed (p.getVelocity().getLength() ?) and damaging them from that. Is there a slightly easier way of doing this?
     
  2. Offline

    Nitnelave

    getVelocity is a vector, with some basic maths you can get the direction the player was moving in.
     
  3. Interesting idea. The problem is that at the point of time where the player already hit the wall, he won't be moving in that direction any more, so your getVelocity() won't point inside the wall.

    You could predict a collision right before it happens: Get the velocity, add it to the player's location, and see if the resulting location is obstructed. Then you can also take the length of the same velocity vector to determine how "hard" the slam was.

    I have no idea how well that actually works, but it's worth a try!

    (summed up: getLocation() of player, add getVelocity() of player --> get block at new coordinates --> check if solid --> take length of getVelocity() to determine speed)
     
Thread Status:
Not open for further replies.

Share This Page