Jump to content

[1.19.2] How to force an entity to face a certain direction?


Recommended Posts

Posted

Heya,

So I'm trying to create a condition that, when activated, forces my entity to face the closest direction they're looking.  For example, if they're looking between north and east and the condition triggers, they'll face north.

Here's how I tried to do it (I did this in the tick() method in the entity class):

if (this.isPetrified()) {
            if (this.getYRot() >= 0 && this.getYRot() < 90) {
                this.setYRot(0.0F);
            }
            else if (this.getYRot() >= 90 && this.getYRot() < 180) {
                this.setYRot(90.0F);
            }
            else if (this.getYRot() >= 180 && this.getYRot() < 270) {
                this.setYRot(180.0F);
            }
            else if (this.getYRot() >= 270 && this.getYRot() < 359) {
                this.setYRot(270.0F);
            } else {
                this.setYRot(0.0F);
            }
        }

This causes the entity to face the certain direction, but if I walk near it, it will occasionally turn and face separate directions.  Any idea what could be causing this?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.