Solved Calculating radial coordinate from position based off vertical yaw?

Discussion in 'Plugin Help/Development/Requests' started by SkittyBoat, Apr 16, 2015.

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

    SkittyBoat

    I'm trying to keep track of a position 1 block behind me from the direction I look, but I've no idea how to do this smoothly!

    Code:
                        
    Location Target = player.getLocation();
    double yaw = Target.getYaw();
    double x = 0, z = 0;
    
    // calculate  X, Z value behind player based on vertical yaw, direction player is facing?
    
    Target.add(x, 0.0D, z);
    entity.teleport(Target);
    
    I'm sure this has to be a common function in many games where you calculate a radial position/coord around a player based on their face direction, can anyone point me to what this calculation would be called? Or.. how to do this?

    EDIT:
    Code:
    Location Target = p.getLocation();
    double yaw = Target.getYaw() - 85;
                         
    double x = 0, z = 0;
                         
    x=Math.cos(yaw*0.02F)*0.2;
    z=Math.sin(yaw*0.02F)*0.2;
                         
    Target.add(x, 0.0D, z);
    entity.teleport(Target);
    
    This is doing what I needed!
    It's keeping an entity following just behind me and stays behind me no matter where I turn.
     
    Last edited: Apr 16, 2015
Thread Status:
Not open for further replies.

Share This Page