EDITED: FIXED>> NO NEED FOR HELP.
i need help with this jumping script:
(UPDATE): I got it to work, I dont know if there is a more efficient way to script this.
void FixedUpdate(){
float straffe = Input.GetAxis ("Horizontal") * speed;
float translation = Input.GetAxis ("Vertical") * speed*multiplier;
bool attack = Input.GetKey (KeyCode.E);
Grounded ();
if (IsGrounded) {
gravity = 0;
moveDirection = new Vector3(straffe,0 , translation);
anim.SetBool ("IsGrounded", true);
canJump = true;
} else {
if (!canJump) {
gravity += 0.1f;
moveDirection = new Vector3(straffe,-gravity , translation);
anim.SetBool ("IsGrounded", false);
}
}
if (canJump) {
if (Input.GetKey (KeyCode.Space)) {
power -= 1;
if (power < 0) {
canJump = false;
}
moveDirection = moveDirection = new Vector3 (straffe, power, translation);
} else {
power = copypower;
canJump = false;
}
}
print (rbody.velocity);
rbody.velocity = moveDirection;
if (translation > 0) {
anim.SetBool ("IsWalking", true);
anim.SetBool ("IsWalkingBack", false);
anim.SetBool ("IsIdle", false);
if (Input.GetKeyDown (KeyCode.LeftShift)) {
anim.SetBool ("IsRunning", true);
multiplier = 2;
}
if (Input.GetKeyUp (KeyCode.LeftShift)) {
anim.SetBool ("IsRunning", false);
multiplier = 1;
}
}else if (translation < 0 ) {
multiplier = 1;
anim.SetBool ("IsWalkingBack", true);
anim.SetBool ("IsWalking", false);
anim.SetBool ("IsIdle", false);
anim.SetBool ("IsRunning", false);
}
else {
multiplier = 1;
anim.SetBool ("IsWalking", false);
anim.SetBool ("IsWalkingBack", false);
if (attack) {
anim.SetBool ("IsIdle", false);
} else {
anim.SetBool ("IsIdle",true);
}
}
if (straffe > 0 || straffe < 0) {
anim.SetBool ("IsWalking", true);
anim.SetBool ("IsIdle", true);
}
if (Input.GetKeyDown ("escape")) {
counter++;
}
}
void Grounded(){
RaycastHit hitInfo;
if(Physics.Raycast(transform.position + (Vector3.up * 0.1f), Vector3.down, out hitInfo, 0.1f))
{
IsGrounded = true;
}
else
{
IsGrounded = false;
}
}
there is no issues with the frames of when i press key down and when it events happens
here is the ground porgram to check if its on the ground
void Grounded(){
RaycastHit hitInfo;
if(Physics.Raycast(transform.position + (Vector3.up * 0.1f), Vector3.down, out hitInfo, 0.3f))
{
IsGrounded = true;
}
else
{
IsGrounded = false;
}
}
Thanks, if you need ANY MORE INFORMATION, JUST ASK!, no question is a stupid one. only answers have the possibility to be stupid.
Follow @SLO_MMORPG