Plugin to invert the movement of a specified player

Discussion in 'Plugin Development' started by player11334share, Feb 7, 2020.

  1. This is all of my code. What it should be doing is essentially inverting the x and z movement of the specified player, instead what it does is just keep me trapped at (0 X, Y can still change ,0 Z). If I activate it anywhere else I just get teleported to (0,0). My guess is that it's something in the onMove() since I was not able to test the velocity part, unless jumping counts as a velocity. Please help, I have been confused for so long now.

    Edit: Just saying. It is probably really badly done and badly optimised but I also don't need it to be too optimised since the most it's ever going to be running on is 3 people on a relatively hefty server.

    Edit 2: Read common mistakes post. Shouldn't store players. Will try.
     

    Attached Files:

    Last edited: Feb 7, 2020
  2. Offline

    bowlerguy66

    @player11334share You're being teleported to 0, 0 because when you do fromX - toX you're getting a very small number as the from and to locations are very small in distance. Then you plug in the numbers to a new location object, which puts you at 0, 0.

    Also, thinking about the logistics of the problem, whenever a player moves and/or changes velocity, you're instantly inverting it which would mean that the players velocity would always be flipping back and forth which would ultimately keep you stuck in one spot.

    One way to solve this might be to make the player go in the opposite direction they're looking but that would still give you problems as a player who presses their backwards key would go forward in the way they are looking.

    Good luck!
     

Share This Page