Solved Force player to look in direction of entity

  • 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!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

MrUrica

New Member
Oct 29, 2018
7
7
0
23
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:
make player look at entity
(This don't work.)

(Skript for 1.8.8 version)

Thanks for your help. Sincerely,
MrUrica.
 
Last edited:
  • Like
Reactions: DavidZar
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.

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
Reactions: DavidZar
Try this:
code_language.skript:
set {_direction} to direction from player to {_entity}

code_language.skript:
on damage:
    set {_direction} to direction from attacker to victim
    send "%{_direction}%" to attacker
    set victim's yaw to {_direction}
    set victim's pitch to {_direction}

No errors, but the victim doesn't change his direction... I'm going to try others possibilities
 
  • Like
Reactions: DavidZar
code_language.skript:
on damage:
    set {_direction} to direction from attacker to victim
    send "%{_direction}%" to attacker
    set victim's yaw to {_direction}
    set victim's pitch to {_direction}

No errors, but the victim doesn't change his direction... I'm going to try others possibilities
Can you show me the value of {_direction} when the attacker hits the victim?
 
  • Like
Reactions: DavidZar
Can you show me the value of {_direction} when the attacker hits the victim?

"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.



I also saw that entities (others than player) didn't have pitch and yaw (variable return <none>)
 
Last edited:
  • Like
Reactions: DavidZar
"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.



I also saw that entities (others than player) didn't have pitch and yaw (variable return <none>)
Try this one:
code_language.skript:
on damage:
    set {_yaw} to attacker's yaw
    set {_pitch} to attacker's pitch
    set {_yaw} to {_yaw} * -1
    set {_pitch} to {_pitch} * -1
    set {_yaw} to "%{_yaw}%.001" parsed as number
    set {_pitch} to "%{_pitch}%.001" parsed as number
    set victim's yaw to {_yaw}
    set victim's pitch to {_pitch}
Please keep in mind that I haven't tested this and may requireaddons.
 
  • Like
Reactions: DavidZar
Try this one:
Please keep in mind that I haven't tested this and may requireaddons.

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
Reactions: DavidZar
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 ?
Try to change this:
  • set {_yaw} to "%{_yaw}%.001" parsed as number
  • set {_pitch} to "%{_pitch}%.001" parsed as number
with this:
  • set {_yaw} to "%{_yaw}%.001" parsed as integer

  • set {_pitch} to "%{_pitch}%.001" parsed as integer
 
  • Like
Reactions: DavidZar
No errors but it's the same thing...
Try this one, I added location since we can't modify an entity's yaw and pitch.
code_language.skript:
on damage:
    set {_yaw} to yaw of attacker
    set {_pitch} to pitch of attacker
    set {_location} to location of victim
    set {_yaw} to {_yaw} * -1
    set {_pitch} to {_pitch} * -1
    if "%{_yaw}%" contains ".":
        set {_yaw} to "%{_yaw}%" parsed as number
    else:
        set {_yaw} to "%{_yaw}%.001" parsed as number
    if "%{_pitch}%" contains ".":
        set {_pitch} to "%{_pitch}%" parsed as number
    else:
        set {_pitch} to "%{_pitch}%.001" parsed as number
    set {_location}'s yaw to {_yaw}
    set {_location}'s pitch to {_pitch}
    teleport victim to {_location}
 
Try this one, I added location since we can't modify an entity's yaw and pitch.
code_language.skript:
on damage:
    set {_yaw} to yaw of attacker
    set {_pitch} to pitch of attacker
    set {_location} to location of victim
    set {_yaw} to {_yaw} * -1
    set {_pitch} to {_pitch} * -1
    if "%{_yaw}%" contains ".":
        set {_yaw} to "%{_yaw}%" parsed as number
    else:
        set {_yaw} to "%{_yaw}%.001" parsed as number
    if "%{_pitch}%" contains ".":
        set {_pitch} to "%{_pitch}%" parsed as number
    else:
        set {_pitch} to "%{_pitch}%.001" parsed as number
    set {_location}'s yaw to {_yaw}
    set {_location}'s pitch to {_pitch}
    teleport victim to {_location}

Works perfectly :emoji_slight_smile:
Thank you so much to help me during 3 days.
 
  • Like
Reactions: DavidZar
Status
Not open for further replies.