Easy way to control mounted mobs

Discussion in 'Plugin Development' started by theninthworldix, Apr 28, 2012.

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

    theninthworldix

    What's an easy way to control the entity a player is mounted to? Since the player is stationary, I cant just send the movement vector of the player to the entity, so I would just assume the easiest approach is the send the player's yaw and pitch to the entity and make it move in that direction. Only problem is, I don't know how to do that nor do I know how to stop the mob from moving on it's normal trajectories.
     
  2. Offline

    r0306

    Not sure but it still might register PlayerMoveEvent. You use it to control the mob's movement depending on the player's direction of movement.
     
  3. Offline

    theninthworldix

    So, just an idea, if I were to do:
    Code:
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent e){
         Player p = e.getPlayer();
         if(p.isInsideVehicle()){
              if(p.getVehicle().getType() == EntityType.PIG){
                   Pig pig = (Pig)p.getVehicle();
              }
         }
    }
    How would I set the pig's yaw and pitch to the player's yaw and pitch and then make the pig move forward when the player presses the W key?
     
  4. you could try something like:
    pig.setVelocity(player.getEyeLocation().getDirection();
    but that's very basic and I'll bet you won't be happy with the result. Also there's no way (without the SpoutPlugin and Spoutcraft) to tell if the player is pressing W while he's inside of a vehicle.
    A more advanced way is what RideThaDragon does: Overwriting Notch code. But that's a not easy...
     
  5. Offline

    theninthworldix

    Haha, I rode a superfast flying pig with the setVelocity one. Is there a way to make it so it doesn't go so fast, it doesn't fly, and it doesn't invert my controls (not sure about the inversion, but it seemed to be doing so)
     
  6. Offline

    Musaddict

    There was a mod I saw before which pathed the vehicle to a bobber on a fishing pole (based on where it landed after you cast it). Maybe try something like that? You could start with something basic, like teleporting the vehicle to where the bobber landed.
     
  7. Offline

    theninthworldix

    Well, I couldn't figure out how to even find the entity for the bobber, so I went with the easier approach of getting the block the player was looking at within 200 blocks whilst holding a feather. I got the pig to teleport to the block, which was good, but when I started treading into the pathing area using setvelocity(not the smartest idea), the pig flew up into the air, fell down through the minecraft world along with all the other mobs and the server crashed.
     
  8. Offline

    Musaddict

    Have you tried setting the velocity with PIE? So, when a player right clicks with a feather, the velocity becomes the player's yaw * the speed you want it?
     
  9. Offline

    theninthworldix

    Not exactly sure how to do that. I've never been good with vector's. Also, the only attributes vectors seem to have is X,Y,Z.
     
  10. Offline

    Musaddict

    Code:java
    1.  
    2. Float dirX = (float) (0 - (Math.sin((player.getLocation().getYaw() / 180) * Math.PI) * 3));
    3. Float dirZ = (float) (Math.cos((player.getLocation().getYaw() / 180) * Math.PI) * 3);
    4. pig.setVelocity(newProj.getVelocity().setX(dirX));
    5. pig.setVelocity(newProj.getVelocity().setZ(dirZ));
    6.  


    There's a way to calculate the X and Z floats. Change the 3 to whatever you feel you need.

    Basically, just merge the 2 things you've done so far; while holding a feather, set the velocity of the pig based on those X and Z values.
     
  11. Offline

    theninthworldix

    That looks like it will work, but I need to ask, what is newProj?
     
  12. a copy&paste error, change it to pig... ;)
     
  13. Offline

    Prgr

    I like the fishing pole and bobber idea, you would set the pig's target to the bobber entity right?
     
  14. Offline

    Musaddict

    yep. Unless you wanted to settle for teleporting, you'd need a pathing API.
     
  15. Offline

    Scyntrus

    I've also been having this problem. I was thinking of making a plugin that involved creatures, but I have no idea how to control them. When I use setVelocity, it sets the velocity of the creature for 1 tick, but then the creature decides to target something else and moves in another direction. Is there a pathing API for creatures?
     
  16. No, you have to overwrite notch code like I did in RideThaDragon. But that's no easy part and you have to leave the bukkit API (That's why I call RTD a mix of a plugin and a mod).
     
  17. As V10lator said there is no other way to control what a mob does than using/overwriting Mojangs code atm.
    I also did this to control the wolves in my MyWolf plugin.
    So if you really want to control them there is no way around the hard part of using Mojangs obfuscated code ;)
    good luck :p
     
  18. Offline

    Scyntrus

    So would you guys be as kind as to make an API out of your code?
     
  19. Offline

    CorrieKay

    Would you mind if i had a chat with ya? ive been looking into a way to make mobs move to specific locations naturally on my own. I know i gotta modify code outside of bukkit, and im not asking you to do it yourself, but maybe you could point me in the right direction? shoot me a conversation or something if you can help. cheers!
     
  20. Offline

    Thumbz

    Bump on the making API for pathfinding. I'm working on a better pigs mod right now too, and without anything but setVelocity, any changing of mob movement is going to be jerky.
     
  21. Offline

    LocoCat

    Did anyone try using a block that has an if loop centered around a keypress boolean on the W key?

    if the boolean is true, then make it set the pigs velocity. if it is false, then don't.
     
  22. Offline

    CorrieKay

    you cant detect if a player is pressing the w key. :\
     
  23. Offline

    LocoCat

    then how does the game detect it so that the player moves forward?
     
  24. Offline

    SirTyler

    The game does, but the server itself does not check.

    As for the API me, dkabot, and _Husky_ are going to attempt to make a Mob API.
     
  25. Offline

    CorrieKay

    oh my gosh, really? :D?

    Thats fantastic! have you guys started? (or rather, do you mind if i ask a question or two?)
     
  26. Offline

    SirTyler

    Haven't started on something coherent, more just research and experimenting right now. And go ahead, ask away.
     
  27. Offline

    CorrieKay

    well if you'd take a look at my thread Basically, all im doing is trying to figure out how to move mobs. As explained inside, apparently pathfinder is sorta... well, not depricated, but its not really used anymore with the new mob ai.

    Have you guys figured out how to utilize the new mob ai to manually move any mob to a location?
     
  28. Offline

    SirTyler

    Like I said, we just started researching. A simple way would be to set up your own path node (just store locations in a list) and use setVelocity to push the mob along the points.
     
  29. Offline

    CorrieKay

    would it look like the mob is walking? What about if they need to jump up a block?
     
  30. Offline

    SirTyler

    No and the jumping will have to be done with the points, pushing them up.
     
Thread Status:
Not open for further replies.

Share This Page