I've translated my controller to C# but I've ran into a little snag that may be little or be gargantuan mass chaos. I must know is the problem the vector3 variable at the top. I believe it was the root of my problem on the other script but I don't see why it would do that. I've checked the values on movedirection and they are changing but my object is not moving. If I haven't been clear enough or you need help deciphering my script leave a comment. If anyone can see the problem or can help to narrow it down please help I know my script is a mess.
public float currentSpeed;
public float walkSpeed = 6.0f;
public float maxSpeed = 15.0f;
public bool swiming = false;
public bool climbing = false;
public float rotateSpeed = 100.0f;
public bool checker = false;
public Vector3 moveDirection = Vector3.zero;
public float jumpSpeed = 8.0f;
public float sprintCurHealth = 0f;
public int sprintMaxHealth = 50;
private int _PercentFull = 100;
public bool isSprinting = false;
float gravity = 20.0f;
private bool grounded = false;
static bool allowMove = true;
static bool playerSneaking = false;
void Awake (){
sprintCurHealth = sprintMaxHealth;
}
void Update(){
if (isSprinting){
currentSpeed = maxSpeed;
}
else {
currentSpeed = walkSpeed;
}
if (Input.GetKey("left shift")){
if (Input.GetKey("w")){
if (sprintCurHealth > 0){
isSprinting = true;
}
if (sprintCurHealth <= 0){
isSprinting = false;
}}
}
if (sprintCurHealth > sprintMaxHealth){
sprintCurHealth = sprintMaxHealth;
}
if (isSprinting){
sprintCurHealth =- Time.deltaTime;
}
if (!isSprinting){
sprintCurHealth =+ Time.deltaTime;
}
transform.Rotate(0,Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime, 0);
}
void FixedUpdate() {
if (Input.GetKeyDown("q")){
//moveDirection.y = jumpSpeed;
animation.Play("roll");
//Roll();
}
if(allowMove){
if (grounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal")*currentSpeed, 0, Input.GetAxis("Vertical")*currentSpeed);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= currentSpeed;
if(!swiming){
if (Input.GetButton("Jump")) {
moveDirection.y = jumpSpeed;
}
if (Input.GetKeyDown("q")) {
moveDirection.y = jumpSpeed;
//Roll();
}
}
}
else if (climbing){
moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"),0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= currentSpeed;
}
}
if(swiming){
currentSpeed = walkSpeed;
}
}
↧