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.