Choppy Diagonal Movement

Updated the Script @ 2113 CST 05/20/13 Note: Realized that there was a portion that wasn’t doing anything

Hey guys/gals! New to these parts and I have ran into an issue, I did some poking around and took care of the issue with Diagonal movement speed, but mine seems to be choppy, so I’m unsure if it’s my code or just how Unity updates, let me know if I made some newbie mistake here… (This is something I’m doing to learn)

Below is a small video of the scene window, I started the video at the point where I started diagonal movement to show that its clunky looking, but before that I showed that the other movements are not like that…
http://www.youtube.com/watch?feature=player_detailpage&v=j_3TMlRKCe8#t=18s

Anyways, here’s the movement code that I’m working with, not the whole script, but if you need it I have no issues posting it, any help would be appreciated.

// Only allow movement and jumps while grounded
		if(grounded) {
			
			if(allowAutoWalk){
				//pushbuffer to avoid on/off flipping
				if(pbuffer>0){
					pbuffer -=Time.deltaTime;
				}
				
				if(pbuffer<0){
					pbuffer=0;
				}	
					
				//Automove Sidebuttonmovement
				if((Input.GetButton("Auto Walk"))  pbuffer == 0){
					pbuffer=coolDown;
					autoWalk = !autoWalk;
				}
					
		    	if(autoWalk  (yInput != 0)){
		    			autoWalk = false;			
				}
	
				if (autoWalk){
					moveDirection.z += 1;	
				}
			
			}
			//movedirection
			moveDirection = new Vector3((Input.GetMouseButton(1) ? Input.GetAxis("Horizontal")* inputModifier : 0) ,0, (Input.GetAxis("Vertical") * inputModifier));
			
			
			speedMod = walkSpeed;
			
			if(isWalking == false){
			 speedMod = runSpeed;
			}
			moveDirection = transform.TransformDirection(moveDirection) * speedMod;
			
		}
			
			UpdateStatus ();
		
		
			// Allow turning at anytime. Keep the character facing in the same direction as the Camera if the right mouse button is down.
			if(Input.GetMouseButton(1)) {
				transform.rotation = Quaternion.Euler(0,Camera.main.transform.eulerAngles.y,0);
			} 
			else{
				transform.Rotate(0,Input.GetAxis("Horizontal"), 0);
			}
			
			//Apply gravity
			moveDirection.y -= gravity * Time.deltaTime;
		
			
		
			//Get CharacterController
			controller = GetComponent<CharacterController>();
		
			//Move Charactercontroller and check if grounded
			grounded = ((controller.Move(moveDirection * Time.deltaTime))  CollisionFlags.Below) != 0;
	}

Thanks!
-Zodiak

Also probably worth noting now that I think about it, that it’s top down, if a scenario in which you need actual game play from the .exe or just the game view itself I will post video or just the .exe its self. Also worth noting that I’ve attempted to split up the moveDirection Vector3 to see if It was an issue with using X axis and the Z axis at the same time, of course as I noted above I’m kinda new to this so I may have even screwed that up. Anyways if I have left any information out that would be useful to point me in the right direction just let me know.

Thanks again.
-Zodiak

Okay, well this is an odd one… Below is some code I tinkered with, seems to have fixed the issue I was having with Diagonal movements (but only slightly).

When I say slightly I mean that in the case of removing my hands from said buttons for diagonal movement it decides it wants to update just real quick the movement of my characters x and z axis separately just for a split second, which in turn makes it looks kind of… buggy? broken? rigged? Anyways…

What’s funky is that if you do diagonal movement using the same Vector #s so… say Vector3 (1, 0, 1) it will make your movement diagonally chunky and make it kinda skip around a bit, but for some odd reason if you make it Vector3 (1, 0, 0.999999) it then allows you to move smoothly in a diagonal direction…

// Only allow movement and jumps while grounded
		if(grounded) {
			
			if(allowAutoWalk){
				//pushbuffer to avoid on/off flipping
				if(pbuffer>0){
					pbuffer -=Time.deltaTime;
				}
				
				if(pbuffer<0){
					pbuffer=0;
				}	
					
				//Automove Sidebuttonmovement
				if((Input.GetButton("Auto Walk"))  pbuffer == 0){
					pbuffer=coolDown;
					autoWalk = !autoWalk;
				}
					
		    	if(autoWalk  (yInput != 0)){
		    			autoWalk = false;			
				}
	
				if (autoWalk){
					moveDirection.z += 1;	
				}
			
			}
			
			//movedirection
			moveDirection = new Vector3((Input.GetMouseButton(1) ? xInput * inputModifier : 0) ,0, (yInput * inputModifier - 0.001f));

			speedMod = walkSpeed;
			
			if(isWalking == false){
			 speedMod = runSpeed;
			}
			
			moveDirection = transform.TransformDirection(moveDirection) * speedMod * 2;
			
		}

Note the moveDirection Vector I have set up changes the yInput (really the z Input) by 0.001f which I’m sure is sloppy to all heck, but this is the only fix I’ve been able to find. So if you can please speak up if there is a better solution to this so it doesn’t look so sloppy.

Thanks again…
-Zodiak

// Only allow movement and jumps while grounded

        if(grounded) {

            if(allowAutoWalk){

                //pushbuffer to avoid on/off flipping

                if(pbuffer>0){

                    pbuffer -=Time.deltaTime;

                }


                if(pbuffer<0){

                    pbuffer=0;

                }   

  
                //Automove Sidebuttonmovement

                if((Input.GetButton("Auto Walk"))  pbuffer == 0){

                    pbuffer=coolDown;

                    autoWalk = !autoWalk;

                }

                    

                if(autoWalk  (yInput != 0)){

                        autoWalk = false;           

                }

    

                if (autoWalk){

                    moveDirection.z += 1;   

                }      

            }

            

            //movedirection

            moveDirection = new Vector3((Input.GetMouseButton(1) ? xInput * inputModifier : 0) ,0, (yInput * inputModifier));

            speedMod = walkSpeed;

            if(isWalking == false){

             speedMod = runSpeed;

            }

            moveDirection = transform.TransformDirection(moveDirection) * speedMod;

            //This allows stuttering or choppy movment (OPTION 1)
            //moveDirection.z = moveDirection.z - 0.001f;

            //This does NOT allow stuttering or choppy movment (OPTION 2)
            //moveDirection.z = moveDirection.z - 0.05f;

        }

I’ve been tinkering with this almost 3 days now, and not a single person can chime in and even remotely say “Yo bro, i have no idea” or “Yo, this is just a Unity issue”, At this moment I’ve kinda thrown up my hands because nothing I do so far makes EVERYTHING move smoothly… If I got with Option 1 (noted on the bottom of the code) your movement with JUST x and JUST y move fluently, but diagonal is choppy or chunky looking, if I go with Option 2 (again noted at the bottom of the code) though the Diagonal movement is more fluent, its lopsided and doesn’t go in a perfect Diagonal way… So can someone that has far more experience then I do speak up on this issue so if it IS a unity issue, I’m not sitting here wasting my time playing with it and can move on to something like learning how to handle Terrain and such. (At the time of writing this 147 Views and the only responses were updates of progress on figuring this damn thing out.)

Thanks
-Zodiak