So… I´ve got a problem. when i move my character and jump at the same time, it sets isGrounded on false so he can´t jump anymore.
But if I jump and then push D so the character moves right, the player flies till he gets to ground.
Here is my code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float sprintSpeed = 7.5f;
public float speed = 5.0f;
public float skok;
public float gravitace;
private float hI;
private Rigidbody2D rb;
public bool jeNaZemi = true;
private bool vPravo = true;
public Vector2 pohybovani;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
Physics2D.gravity *= gravitace;
}
// Update is called once per frame
void Update()
{
hI = Input.GetAxisRaw("Horizontal");
if (Input.GetKey(KeyCode.D))
{
rb.velocity = new Vector2(speed, 0);
}
if (Input.GetKey(KeyCode.A))
{
rb.velocity = new Vector2(-speed, 0);
}
if (Input.GetKey(KeyCode.LeftShift))
{
}
if (Input.GetKeyDown(KeyCode.Space) && jeNaZemi)
{
rb.AddForce(Vector3.up * skok, ForceMode2D.Impulse);
jeNaZemi = false;
}
if (vPravo == false && hI > 0)
{
Pretocit();
}
else if (vPravo == true && hI < 0)
{
Pretocit();
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
jeNaZemi = true;
}
void Pretocit()
{
vPravo = !vPravo;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
private void FixedUpdate()
{
}
}