Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » my jump doesnt work?

my jump doesnt work?

View previous topic View next topic Go down  Message [Page 1 of 1]

1 my jump doesnt work? on Sat Aug 01, 2015 1:10 pm

Zachvlol


Member [Lv. 3]
Member [Lv. 3]
jump script
Code:
using UnityEngine;
using System.Collections;

public class Bounce : MonoBehaviour {

   float atbTime;
   float currentatbTime;
   float perc = 1;

   Vector3 startPos;
   Vector3 endPos;
   
   bool firstInput;
   public bool justJump;
   
   // Update is called once per frame
   void Update () {
       if (Input.GetButtonDown ("up") || Input.GetButtonDown ("down") || Input.GetButtonDown ("left") || Input.GetButtonDown ("right") || Input.GetButtonDown ("space")) {
         if(perc == 1)
         {
            atbTime = 1;
            currentatbTime = 0;
            firstInput = true;
            justJump = true;
         }
      }
      startPos = gameObject.transform.position;

      if(Input.GetButtonDown ("right") && gameObject.transform.position == endPos) {
         endPos = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z);
      }
      if(Input.GetButtonDown ("left") && gameObject.transform.position == endPos) {
         endPos = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z);
      }
      if(Input.GetButtonDown ("up") || Input.GetButtonDown ("space") && gameObject.transform.position == endPos) {
         endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1);
      }
      if(Input.GetButtonDown ("down") && gameObject.transform.position == endPos) {
         endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z - 1);
      }
      if (firstInput == true) {
         currentatbTime += Time.deltaTime * 5;
         perc = currentatbTime / atbTime;
         gameObject.transform.position = Vector3.Lerp (startPos, endPos, perc);
         if(perc > 0.8) {
            perc = 1;
         
         }
         if(Mathf.Round(perc) == 1) {
            justJump = false;
         }
      }
   }
}
animation controller script
Code:

using UnityEngine;
using System.Collections;

public class animController : MonoBehaviour {

   Animator anim;
   public GameObject thePlayer;

   // Use this for initialization
   void Start () {
      anim = gameObject.GetComponent<Animator> ();
   }
   
   // Update is called once per frame
   void Update () {
      Bounce bounceScript = thePlayer.GetComponent<Bounce> ();
      if (bounceScript.justJump == true) {
         anim.SetBool ("Jump", true);
      }
      else {
         anim.SetBool ("Jump", false);
      }
   }
}

View user profile

2 Re: my jump doesnt work? on Tue Sep 08, 2015 12:35 pm

supamigit


Member [Lv. 3]
Member [Lv. 3]
Working fine for me...

I did however change your Up Down and LEFT and RIGHT to respected WASD keys using Keycode.Space etc... 

not sure what we are missing here... 

do you have a screen y of your inspector holding the player bits and bobs#?

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum