1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Force player to look in direction of entity

Discussion in 'Skript' started by MrUrica, Oct 29, 2018.

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

    MrUrica New Member

    Joined:
    Oct 29, 2018
    Messages:
    7
    Likes Received:
    7
    Hello,
    After no answers in a french website, I try to have one here.

    I'm trying to make a player look at entity or a coordinate (set in a variable). Is it possible ?
    Something like:
    Code (Text):
    1. make player look at entity
    (This don't work.)

    (Skript for 1.8.8 version)

    Thanks for your help. Sincerely,
    MrUrica.

     
    #1 MrUrica, Oct 29, 2018
    Last edited: Oct 29, 2018
    • Like Like x 1
  2. Best Answer:
    Post #12 by Andalmere, Oct 31, 2018
  3. Andalmere

    Andalmere Active Member

    Joined:
    Jan 28, 2017
    Messages:
    63
    Likes Received:
    10
    Get the yaw and pitch of the player from the player's direction towards the entity and store it on a variable. Then modify the player's yaw and pitch using that variable.
     
    • Like Like x 1
  4. MrUrica

    MrUrica New Member

    Joined:
    Oct 29, 2018
    Messages:
    7
    Likes Received:
    7
    Thanks for your help, but have you any line to give me please ? I tried a lot of things but that was a failure :/
     
    • Like Like x 1
  5. Andalmere

    Andalmere Active Member

    Joined:
    Jan 28, 2017
    Messages:
    63
    Likes Received:
    10
    Try this:
    Code (Skript):
    1. set {_direction} to direction from player to {_entity}
     
    • Like Like x 1
  6. MrUrica

    MrUrica New Member

    Joined:
    Oct 29, 2018
    Messages:
    7
    Likes Received:
    7
    Code (Skript):
    1.  
    2. on damage:
    3.     set {_direction} to direction from attacker to victim
    4.     send "%{_direction}%" to attacker
    5.     set victim's yaw to {_direction}
    6.     set victim's pitch to {_direction}
    No errors, but the victim doesn't change his direction... I'm going to try others possibilities
     
    • Like Like x 1
  7. Andalmere

    Andalmere Active Member

    Joined:
    Jan 28, 2017
    Messages:
    63
    Likes Received:
    10
    Can you show me the value of {_direction} when the attacker hits the victim?
     
    • Like Like x 1
  8. MrUrica

    MrUrica New Member

    Joined:
    Oct 29, 2018
    Messages:
    7
    Likes Received:
    7
    "1.15 meters west and 1.81 meters north". The message change with the distance, and position (north, east, south or west) between attacker and victim.

    [​IMG]

    I also saw that entities (others than player) didn't have pitch and yaw (variable return <none>)
     
    #7 MrUrica, Oct 31, 2018
    Last edited: Oct 31, 2018
    • Like Like x 1
  9. Andalmere

    Andalmere Active Member

    Joined:
    Jan 28, 2017
    Messages:
    63
    Likes Received:
    10
    Try this one:
    Code (Skript):
    1. on damage:
    2.     set {_yaw} to attacker's yaw
    3.     set {_pitch} to attacker's pitch
    4.     set {_yaw} to {_yaw} * -1
    5.     set {_pitch} to {_pitch} * -1
    6.     set {_yaw} to "%{_yaw}%.001" parsed as number
    7.     set {_pitch} to "%{_pitch}%.001" parsed as number
    8.     set victim's yaw to {_yaw}
    9.     set victim's pitch to {_pitch}
    Please keep in mind that I haven't tested this and may requireaddons.
     
    • Like Like x 1
  10. MrUrica

    MrUrica New Member

    Joined:
    Oct 29, 2018
    Messages:
    7
    Likes Received:
    7
    No errors, but entities doesn't change their direction... When I become victim and entity attacker, {_yaw} and {_pitch} returns 0

    Possibly a skript version problem ?
     
    • Like Like x 1
  11. Andalmere

    Andalmere Active Member

    Joined:
    Jan 28, 2017
    Messages:
    63
    Likes Received:
    10
    Try to change this:
    with this:
     
    • Like Like x 1
  12. MrUrica

    MrUrica New Member

    Joined:
    Oct 29, 2018
    Messages:
    7
    Likes Received:
    7
    No errors but it's the same thing...
     
    • Like Like x 1
  13. Andalmere

    Andalmere Active Member

    Joined:
    Jan 28, 2017
    Messages:
    63
    Likes Received:
    10
    Try this one, I added location since we can't modify an entity's yaw and pitch.
    Code (Skript):
    1. on damage:
    2.     set {_yaw} to yaw of attacker
    3.     set {_pitch} to pitch of attacker
    4.     set {_location} to location of victim
    5.     set {_yaw} to {_yaw} * -1
    6.     set {_pitch} to {_pitch} * -1
    7.     if "%{_yaw}%" contains ".":
    8.         set {_yaw} to "%{_yaw}%" parsed as number
    9.     else:
    10.         set {_yaw} to "%{_yaw}%.001" parsed as number
    11.     if "%{_pitch}%" contains ".":
    12.         set {_pitch} to "%{_pitch}%" parsed as number
    13.     else:
    14.         set {_pitch} to "%{_pitch}%.001" parsed as number
    15.     set {_location}'s yaw to {_yaw}
    16.     set {_location}'s pitch to {_pitch}
    17.     teleport victim to {_location}
     
    • Like Like x 3
  14. MrUrica

    MrUrica New Member

    Joined:
    Oct 29, 2018
    Messages:
    7
    Likes Received:
    7
    Works perfectly :emoji_slight_smile:
    Thank you so much to help me during 3 days.
     
    • Like Like x 1
    • Friendly Friendly x 1
Thread Status:
Not open for further replies.

Share This Page

Loading...