Solved Momentum

Discussion in 'Plugin Development' started by BlueMustache, Feb 22, 2014.

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

    BlueMustache

    Hey.
    I am making a plugin that involves momentum.
    How might I, when a player causes a playerteleportevent, take their velocity before they teleported, and set their velocity to that after they teleport.
    Similar concept to portals. Speedy thing comes in, speedy thing goes out. Also, this is essentially a portal gun plugin. (Attempting to make the best one out there) I have another problem that may occur, when I jump into the block on the ground I designate, and It teleports me, I want my momentum to go upward. BTW, this plugin isn't just designed to be a port of portal, but a port of the Source Engine! If anyone want's to help me, I need all the help I can get!
    Thanks,
    - Blue
     
  2. Offline

    werter318

    BlueMustache
    You have look at the rotation of the 2th portal, and change the velocity based on that.
     
  3. Offline

    BlueMustache

    I know that.
    Do you have example code for a momentum script?
     
  4. Offline

    Ironraptor3

    BlueMustache
    Before you teleport them, save the player.getVelocity(). Then once they teleport, use player.setVelocity(VelocityYouSaved); If they are changing directions while teleporting, insert some logic to check that, and if anything is the opposite, multiply that cord by -1
     
  5. Offline

    BlueMustache

    Thanks, I thought that was it. Just checking.
    Although, you can't save a velocity into a hashmap can you?
     
  6. Offline

    Ironraptor3

    Code:java
    1. new HashMap<String, Vector> velocities = new HashMap<String, Vector>();
    2.  
    3. velocities.put(player.getName(), player.getVelocity()):
    4.  
    5. velocities.get(player.getName());
     
    BlueMustache likes this.
  7. Offline

    Gamecube762

    I had a simple script I made to make sponges bouncy(only to find out mojang is using the same method for the slime blocks...). The code is simple, just take the player's Y velocity and times it by -1
    Code:java
    1. Player p = e.getPlayer();
    2. Vector v = p.getVelocity();
    3.  
    4. v.setY(v.getY * -1);
    5. p.setVelocity(v);
     
    BlueMustache likes this.
  8. Offline

    BlueMustache


    Thanks guys! Problem solved. :)
     
Thread Status:
Not open for further replies.

Share This Page