Spawn Mob in Front of the player

Discussion in 'Plugin Development' started by desup, Jan 22, 2012.

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

    desup

    Hello, and sorry for second thread today.
    I know how to spawn mob at players location.
    But when the player is walking, he will not see the mob.
    Is it possible to spawn mob like 3 block in front of the player?
    I tried to use subtract(), but I don't know, if the player is looking to x or z.
    Can you help me?
    I know it will possibly be easy as a slap, but I am noob :(.
    Thank you :)
     
  2. I am sure there is a method that goes something like

    player.getDirection()

    and then you could do

    player.getDirection().add(3)

    Please excuse me if I am wrong.

    Keir
     
  3. Offline

    desup

    I don't know where is problem

    Yes, now i understood, it is for Location, but .add(3) is not working

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  4. Offline

    nisovin

    Location location = player.getLocation().toVector().add(player.getLocation().getDirection().multiply(3)).toLocation(player.getWorld());
     
    mollekake likes this.
  5. Offline

    desup

    Wow, thanks! I will not try to understand this :D.
    And I Love your plugin BookWorm ;)
     
  6. Offline

    nisovin

    It's really not hard to understand. Breaking it up into multiple lines might make it clearer:
    Code:
    Vector vec = player.getLocation().toVector(); // get player's location vector
    Vector dir = player.getLocation().getDirection(); // get player's facing
    vec = vec.add(dir.multiply(3)); // add player's direction * 3 to the location (getting ~3 blocks in front of player)
    Location location = vec.toLocation(player.getWorld()); // convert back to location
    
     
  7. Offline

    desup

    Yes, Finally understood man, thanks for patience ;)
     
  8. Wow, I was slightly right :D
     
Thread Status:
Not open for further replies.

Share This Page