Jump to content

Recommended Posts

Posted (edited)

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;
			 dx=nextPos.x-player.posX+0.5D;
			 dy=nextPos.y-player.posY;
			 dz=nextPos.z-player.posZ+0.5D;
			 
			 dist=Math.sqrt(dx*dx+dy*dy+dz*dz);
			 
			 //Check if we were moved or something interfered with us and give control back to user
			 if(prev_dist!=-1 && dist>prev_dist+2) {
				 prev_dist=-1;
				 Main.cancelAllMovement();
				 return;
			 }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
				 path.remove(0);
				 prev_dist=-1;
				 
				 if(path.size()==0) {
					move.setForward=0;//if there's another path to follow after this one don't stop..."smooth" walking
					Main.pathToFollow.remove(0);
				 }
			 }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.moveForward;
            this.forwardKeyDown = true;
        }
        else
        {
            this.forwardKeyDown = false;
        }

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

        if (this.gameSettings.keyBindLeft.isKeyDown() || setSides==-1)
        {
            ++this.moveStrafe;
            this.leftKeyDown = true;
        }
        else
        {
            this.leftKeyDown = false;
        }

        if (this.gameSettings.keyBindRight.isKeyDown() || setSides==1)
        {
            --this.moveStrafe;
            this.rightKeyDown = true;
        }
        else
        {
            this.rightKeyDown = false;
        }

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

Edited by Antonii
Posted (edited)

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
Posted

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

About Me

Spoiler

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)

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.