Jump to content

Simulating keyboard- Moving player while keeping rotationYaw


Recommended Posts

I am making a robot mod. The problem I have is that the code I created makes the player look only in one direction: the one in which he walks. I want to allow the yaw rotation to be manually  controlled  while maintaining the same walking direction. Here's my code:

if(Main.pathToFollow.size()>0) {
//Main.pathToFollow is an list of lists-every path is a list of nodes and I will have multiple paths to follow;
			 ArrayList<PathPoint> path=Main.pathToFollow.get(0);
			 PathPoint nextPos=path.get(0);
			 double dx,dy,dz;
			 double dist;
			 //Check if we were moved or something interfered with us and give control back to user
			 if(prev_dist!=-1 && dist>prev_dist+2) {
			 }else prev_dist=dist;
			 if(dist>2) {
				 if(!player.isSprinting()) player.setSprinting(true);
			 }else if(!player.isSprinting()) player.setSprinting(false);//if close to destination shutdown sprinting or we'll miss it
			 if(dist<=0.25D) {
				 // is within targeted block
				 //get the next one
				 if(path.size()==0) {
					move.setForward=0;//if there's another path to follow after this one don't stop..."smooth" walking
			 }else {
				// Face next block
			    float f = (float)(MathHelper.atan2(dz, dx) * (180D / Math.PI)) -90.0f;
			    player.rotationYaw = Main.updateRotation(player.rotationYaw, f, 179.0f);  
			    //double side_amount=Math.cos(Math.toRadians(f))*1;  //1 is amount=1 block
			    //double forward_amount=-Math.sin(Math.toRadians(f))*1;
			    //if side_amount>0.21 then setSide    ....<- is this correct? I hate the 0.21 constant
			    move.setForward=1;  // It's easier to just walk straight ...I don't have to know the typical walking distance when a genuine keypressed event is fired. The amount depends and the ground material : ~0.21
			    if(dy>0) player.jump();			    

 I know that a player moves about 0.21(lowest I have seen) units when a key is pressed. But from the code it looks it depends on the ground material. If I delete the player.rotationYaw code how should I set the left/right/forward/bacwards amount?

Here's the new movement class that deals with keyboard input: it contains the setForward/setJump and setSide:

        if (this.gameSettings.keyBindForward.isKeyDown() || setForward==1)
            this.forwardKeyDown = true;
            this.forwardKeyDown = false;

        if (this.gameSettings.keyBindBack.isKeyDown() || setForward==-1)
            this.backKeyDown = true;
            this.backKeyDown = false;

        if (this.gameSettings.keyBindLeft.isKeyDown() || setSides==-1)
            this.leftKeyDown = true;
            this.leftKeyDown = false;

        if (this.gameSettings.keyBindRight.isKeyDown() || setSides==1)
            this.rightKeyDown = true;
            this.rightKeyDown = false;

So for controlling walking path I can only set setForward /setSides to +-1. A solution?

Edited by Antonii
Link to comment
Share on other sites

What I ask is this:

  I have an origin and a target. I know the distance and the angle I need to get there. I don't know by what amount I move in a direction because it depends on the blocks beneath me. I know that I have arrived at the destination when dist<0.25 units.


  If I press in the same time left and forawrd I will go on 45deg angle. Let's say the angle is 15.  How many times should I press left /forward so that I don't get away too much from the original planned path. It looks very similar to PWM (pulse width modulation)


Edited by Antonii
Link to comment
Share on other sites

Have a look at any blocks you can think of that move the player. Flowing Water? Piston

About Me


My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

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.

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.


  • Create New...

Important Information

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