- Home /
Character triple+ Jumping: Please Help!
So, I am very new to unity, and this is probably a stupid question with a simple answer. Anyways, I "improved" the simple 'Roll a Ball' PlayerController script for my player object, but when I make my player character jump, I can keep jumping by pressing space (press space quickly 3x, triple jump, 4x, quadruple jump, and so on) and as the game is a platformer, it ruins the skill aspect to it, allowing the player to essentially fly to each section of the map. So if anyone can help me with this problem, it would be greatly appreciated (by the way, I still want my player object to jump and double jump). Here's the script:
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
winText.text = "";
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
float jump;
if (Input.GetKeyDown(KeyCode.Space))
jump = 20f;
else
jump = 0;
Vector3 movement = new Vector3(moveHorizontal, jump, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if (count >= 12)
{
winText.text = "You Win!";
}
}
}`
Your answer
Follow this Question
Related Questions
Can't declare a joystick 0 Answers
Player keeps flying up 0 Answers
I need help with a movement script 1 Answer
How to prevent player from moving in air while jumping in place?? 0 Answers