Solved Called event when player moves on vehicle?

Discussion in 'Plugin Development' started by Symphonic, Jan 3, 2020.

  1. Offline

    Symphonic

    I've came across a little bit of a tricky trig.. I'm developing a spaceship plugin and I want to be able to capture when a player uses WASD but also seat them on top of an armorstand, or any entity for that matter, I could always make it invisible. I'm just not sure how to go about getting movement from a player like that.
     
  2. Offline

    Niv-Mizzet

    You could use a horse, or you could have a pig on a saddle, with a retextured carrot on a stick.
    I don't know if it works with entities, but you possibly could use a PlayerMoveEvent.

    You could also not have them riding on it, but instead check for a right click, teleport them to the same position of the vehicle, and then check for PlayerMoveEvents and teleport the vehicle to where the player is standing. I know there is a way to also check for sneak so they could dismount for commands, so probably also for plugins.

    Scroll around the passenger area in the Javadocs: https://hub.spigotmc.org/javadocs/b...y.html#addPassenger-org.bukkit.entity.Entity-

    Hope this helps
     
    Last edited: Jan 3, 2020
  3. Offline

    Symphonic

    The issue with all these ideas would be filtering out where the player is teleported to the spaceship and only capturing input
     
  4. Offline

    Niv-Mizzet

    @Symphonic is the spaceship an entity or a moving collection of blocks?
    Also, what Minecraft version is your server/plugin in.
    If it's an entity, you could use a boat.
     
  5. Offline

    Symphonic

    Its going to be FallingBlocks, 1.14, how would I go about doing that with a boat
     
  6. Offline

    Niv-Mizzet

    1. Boats are entities
    2. boats sense player movement, even on land
    3. take the boat and constantly be teleporting the FallingBlocks relative to the boat.
    to fly you could have them hold an item in their hand, right click to turn up engine, and left click to turn down
     
  7. Offline

    Symphonic

    I don't want the boat to directly be moved, I want to take wasd input to make a different movement scheme
     
  8. Offline

    Niv-Mizzet

    @Symphonic What would the movement scheme be; what would each key do?
     
  9. Offline

    Symphonic

    W and S will still be for acceleration and deceleration, but I was thinking the mouse position could be for pitch and yaw. I have an idea on how to do this but I have no idea on how to work with velocity, e.g. Take the forward velocity of the boat and then add vertical velocity based on the pitch of the player.
     
  10. Offline

    Niv-Mizzet

    @Symphonic
    For pitch and yaw: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Location.html#getYaw--

    W and S should be simple enough, just modify the attribute GENERIC_MOVEMENT_SPEED(Docs down below) by a certain amount each time the boat "moves".

    Here's an idea of what you need to do for velocity (Note: for water you will need to calculate buoyancy, which is a whole different topic).
    Please note I am not a physics expert.
    For the velocity, acceleration due to gravity is 9.8 m/s^2. Terminal velocity calculator here: http://www.calctool.org/CALC/eng/aerospace/terminal

    For terminal velocity: Cross section, in simpler terms, is the area of the bottom of the vessel, projected into 2d land. You could probably calculate the cross section in the same way they calculate shadows, though I'm not sure how they do that, you'd have to ask timtower or some other really good plugin dev., or do some research on your own. Possibly you could create an invisible light source in the sky and calculate light level. For medium density, just take all the blocks you are using, take their real-world densities(if they have one), and multiply by the amount of blocks of that you are using, then divide by total block amount. For example, let's say you are using clay and blue concrete. Call clay density c, and blue concrete density b. Say you are using 10 clay and 6 blue concrete. So, your medium density equation would be (10c+6b)/16. Drag coefficient is explained in the notes section of the web page.

    As for increasing speed, you can modify the attribute GENERIC_MOVEMENT_SPEED: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/attribute/Attribute.html#GENERIC_MOVEMENT_SPEED
     
    Last edited: Jan 6, 2020
  11. Offline

    Symphonic

    Thanks!
     
  12. Offline

    Niv-Mizzet

    You are very welcome!
     

Share This Page