Paste #39922: Untitled Paste

Date: 2017/02/14 15:39:15 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


setFacing:
  type: task
  debug: minimal

  script:
  - define vector <procedure[script:getDirectionVector|from:<entity[<def[entity]>].location>|to:<def[target]>].vector>
  - define pitch <procedure[script:getFacingPitch|y:<def[vector].y>].pitch>
  - define yaw <procedure[script:getDirectionVector|x:<def[vector].x>|z:<def[vector].z>].yaw>
  - editentity <entity[<def[entity]>]> rotation:<def[pitch]>,<def[yaw]>,0


getDirectionVector:
# Usage: <procedure[script:getDirectionVector|from:x,y,z|to:x,y,z].vector>
# <procedure[script:getDirectionVector|from:<player.location>|to:<player.location.world.entities[armor_stand].get[1].location>].vector>
  type: procedure
  debug: false
  script:
    - determine vector <location[<context.from>].subtract[<context.to>].normalized>


getFacingYaw:
# Usage: <procedure[script:getDirectionVector|x:x|z:z].yaw>
  type: procedure
  debug: false
  script:
    # PI 3.14159265359
    # 180 / PI == 57.295779513
    - define radians <context.x.atan2[<context.z>]>
    - define degrees <def[radians].multiply[57.295779513]>
    - if <def[degrees]> < 0:
      - define degrees <def[degrees].add[360]>
    - determine yaw <def[degrees]>


getFacingPitch:
# Usage: <procedure[script:getFacingPitch|y:y].pitch>
  type: procedure
  debug: false
  script:
    # PI 3.14159265359
    # 180 / PI == 57.295779513
    - determine pitch <context.y.multiply[57.295779513]>