Turn only player head while riding custom entity

Started by Qsome on

Topic category: Advanced modding

Last seen on 21:12, 25. Jul 2022
Joined Jul 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Turn only player head while riding custom entity

I have made a rideable entity, but need to be able to turn ONLY the player's head with the mouse (like vanilla boats, which use "A" and "D" to turn the boat, but allow the player head to turn freely, while the body changes direction with the boat).

I can make the entity not rotate with the player's direction by changing this bit (the only part related to rotation) of the entity's auto-generated code by MCreator (the bold is what I changed):


@Override
        public void travel(Vec3d dir) {
            Entity entity = this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0);
            if (this.isBeingRidden()) {
                this.rotationYaw = entity.rotationYaw;
                this.prevRotationYaw = this.rotationYaw;
                this.rotationPitch = entity.rotationPitch * 0.5F;
                this.setRotation(this.rotationYaw, this.rotationPitch);
                this.jumpMovementFactor = this.getAIMoveSpeed() * 0.15F;
                this.renderYawOffset = entity.rotationYaw;
                this.rotationYawHead = entity.rotationYaw;
                this.stepHeight = 1.0F;


to:


@Override
        public void travel(Vec3d dir) {
            Entity entity = this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0);
            if (this.isBeingRidden()) {
                this.rotationYaw = this.rotationYaw;
                this.prevRotationYaw = this.rotationYaw;
                this.rotationPitch = this.rotationPitch * 0.5F;
                this.setRotation(this.rotationYaw, this.rotationPitch);
                this.jumpMovementFactor = this.getAIMoveSpeed() * 0.15F;
                this.renderYawOffset = this.rotationYaw;
                this.rotationYawHead = this.rotationYaw;
                this.stepHeight = 1.0F;


Which simply stops syncing the entity direction to the player direction. The problem, is that the player can rotate their entire body 360 degrees with the mouse, not just their head. This odd spinning ability can be prevented by setting the new:


this.rotationYaw = this.rotationYaw;


to:


entity.rotationYaw = this.rotationYaw;


Reversing the intent of the original code by syncing the player direction to the entity direction. The problem now, is that this applies to the body AND head, not just the body (though I can still look up and down, as the pitch is unaffected).

Does anyone know how to set only the player's body to the entity's rotation, without locking the head in place?

 

P.S. Only the "Rideable" and "forward movement control" checkboxes are enabled.

Last seen on 19:13, 24. May 2021
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
There is a strafe control…
Mon, 08/24/2020 - 19:24

There is a strafe control option in mcreators is entity rideable area. This is what you are looking for.

Last seen on 21:12, 25. Jul 2022
Joined Jul 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Good suggestion, that does…
Thu, 09/03/2020 - 07:39

Good suggestion, that does help the head to turn independent of the body, however once the player turns far enough the body begins turning with the head (just like when standing still normally). This also allows strafing, which will not work in this instance.

I discovered that only an entity's body can be controlled with the "renderYawOffset" variable according to this website (http://greyminecraftcoder.blogspot.com/2015/07/entity-rotations-and-animation.html), however I can't reverse the code and say:

entity.renderYawOffset = this.rotationYaw;

It doesn't recognize the "renderYawOffset" if it is prefixed by "entity". I'm guessing that the player's "renderYawOffset" is not able to be modified from another entity, however I don't know how to combat this if it is the problem.

 

Last seen on 14:43, 2. Aug 2022
Joined Nov 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Did you try looking at the…
Fri, 09/04/2020 - 09:54

Did you try looking at the boat class?

Last seen on 21:12, 25. Jul 2022
Joined Jul 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I haven't figured out how…
Thu, 09/24/2020 - 17:37

I haven't figured out how. Do you know where I'd find it?

Last seen on 14:43, 2. Aug 2022
Joined Nov 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
There is a button left of…
Fri, 09/25/2020 - 18:25

There is a button left of the workspace tab. It is a pointed arrow. Click it and the source code will be revealed. Go to the external libraries and go to forge -> net -> minecraft.

Last seen on 19:58, 15. Dec 2021
Joined Dec 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
where is that>>    
Wed, 12/08/2021 - 04:48

where is that>>

 

 

Last seen on 06:38, 4. Jan 2024
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Live does not return when…
Sat, 11/04/2023 - 04:34

Live does not return when clicking A, D