Pig Race

Discussion in 'Plugin Development' started by Bikkel007, Apr 28, 2014.

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

    Bikkel007

    Hey guys,

    I have a problem when I try to spawn a pig for players to race on. I have the following method to mount a player on a pig:

    Code:java
    1. public void mountpig(Player speler)
    2. {
    3. Pig pig = (Pig)speler.getWorld().spawnEntity(speler.getLocation(),EntityType.PIG);
    4. pig.teleport(speler.getLocation());
    5. pig.setSaddle(true);
    6. pig.setPassenger(speler);
    7. speler.setItemInHand(new ItemStack(Material.CARROT_STICK));
    8. }


    The pig gets spawned but it's not moving at all. It takes like 20 seconds before the pig is reacting to my carrot stick, while when mounting a pig normally it reacts right away. Any idea how I can fix this?

    Kinds regards,
    Bikkel007
     
  2. Offline

    MrKeals

  3. Offline

    Bikkel007

    MrKeals
    So you mean something like this:
    Code:java
    1. @EventHandler
    2. public void OnPlayerMove (PlayerMoveEvent event)
    3. {
    4. if (event.getPlayer().getVehicle() instanceof Pig == true)
    5. {
    6. event.getPlayer().getVehicle().setVelocity(event.getPlayer().getVelocity());
    7. }
    8. }

    It isn't working the way it is right now. Any suggestions?

    N3rdFall Yep that's working. Thanks ;) Even though it's working, the pig is going way too fast. Is it possible to slow it down?

    EDIT. Never mind, found it :)
    Code:java
    1. event.getPlayer().getLocation().getDirection().multiply(0.25)


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page