How to make a player directly at another living entity

Discussion in 'Plugin Development' started by WiseHollow, Jan 11, 2015.

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

    WiseHollow

    Is there a way to make "Player player" look at "LivingEntity entity" ? I have trying to get this working for a while but am not sure. Does anyone have some insight on this?
     
  2. Offline

    teej107

    What have you tried?
     
  3. Offline

    WiseHollow

    What I have tried isn't even close to an answer, so I am looking for advice. Can you give some insight?
     
  4. Offline

    teej107

    @WiseHollow Well we would like to know if you have put any effort into this. You would have to get both entities locations and make the correct calculations by setting the yaw and pitch.
     
  5. Offline

    WiseHollow

    I am not someone to ask for assistance unless I have attempted at something for quite a length of time. The only reason I have not put any code on here is because three reasons.
    1. I was working on this maybe 4 months ago and after giving up, supplemented the code with a lazy-way of doing something similar, but not quite how I wanted. So I do not have my old code.
    2. Just now started looking at it again and feel the same puzzled feeling.
    3. I think it would involve Vectors and this is a new field to me.
    However, since you seen to wanna see an attempt, here ya go!
    Code:
                       Location target = damager.getLocation().clone().getDirection().multiply(-2).toLocation(damager.getLocation().getWorld());
                     
                        target.setPitch(damager.getLocation().getPitch());
                        target.setYaw(damager.getLocation().getYaw());
                     
                        if (target.getBlock().getType() == Material.AIR)
                            damaged.teleport(target);
    
    That is an attempt to move behind the entity by 2 block-spaces, and look in their direction.
     
  6. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page