Movement help please

I got a pretty good script so far and I just have a few problems.

  • How do I get my character to keep going just a bit with same velocity over a edge instead of just completely stopping when I run off something.

  • How would I slow speed based on the slop of a hill and or stop you if it is to steep.

//Position
var currentposition = 1;
//Normal = 1
//Sprinting = 2
//Crouching = 3

//Speeds
var CurrentSpeed = 0;
private var AverageSpeed = 4.25;
private var SprintingSpeed = 7.25;
private var CrouchingSpeed = 2.25;


//Move Direction Vector Variable
var moveDirection : Vector3;






/////////////////////////////////////////////////////////////////////////////////////////////
function FixedUpdate () {

	//Check Inputs for movement
	if (Physics.Raycast(transform.position, -transform.up, 1)){
	var moveDirection = Vector3(Input.GetAxis("Horizontal")*CurrentSpeed*Time.deltaTime, 0, Input.GetAxis("Vertical")*CurrentSpeed*Time.deltaTime);
	}else{
	
		moveDirection = Vector3();
		
	}
	
	
	
	// Check If Moving for Sprinting
	if(Input.GetButton("Vertical") || Input.GetButton("Horizontal")){
		// Sprinting
		if(Input.GetButton("Sprint")  Input.GetAxis("Vertical")>0){
			CurrentSpeed = SprintingSpeed;
			currentposition = 2;
		}else{
			if(!Input.GetButton("Crouch")  !Input.GetButton("Sprint") || !Input.GetButton("Crouch")  Input.GetAxis("Vertical")<0 || !Input.GetButton("Crouch")  !Input.GetButton("Vertical")){
				CurrentSpeed = AverageSpeed;
				currentposition = 1;
			}
		}
	}
	
	
	
	//Crouching
	if(Input.GetButton("Crouch")  !Input.GetButton("Sprint")){
		CurrentSpeed = CrouchingSpeed;
		currentposition = 3;
	}else{
		if(!Input.GetButton("Crouch")  !Input.GetButton("Sprint")){
			CurrentSpeed = AverageSpeed;
			currentposition = 1;
		}
	}
/////////////////////////////////////////////////////////////////////////////////////////////	




/////////////////////////////////////////////////////////////////////////////////////////////
transform.Translate(moveDirection);
/////////////////////////////////////////////////////////////////////////////////////////////
}

Extra Question

-How would you go about a takout such as getting behind someone locking both while the other moves into position and stabs the other. Like the one you see in BF3 he walks up and smoothly gets into place and you cant control while your performing the takeout.

With regards to momentum, store his velocity ? If there is no contact with the ground apply the last velocity to the player each frame reducing it every time whilst applying gravity as well and he should fall in a short arc.

With regards to slowing down have a loot at the raycast function more closely , get the return values from it and look at the normal of the collision point, this will tell you how steep the slope is.

With regards to the takeouts… thats going to require synced animations between both characters, probably one to work on later :wink:

"How would you go about a takout such as getting behind someone locking both while the other moves into position and stabs the other. Like the one you see in BF3 he walks up and smoothly gets into place and you cant control while your performing the takeout. "

Think I know what you mean, that’s actual gameplay. That’s getting into AI and knife combat, which depends on animation as well as maybe using an AI waypoint (look it up across the forum/docs). However, do you want the AI walking to this position while the player sneaks up behind and then put the “what if” the AI sees the player before getting to his end walking position? There’s a lot to AI.