Unity 3D TR Forum

Orjinalini görmek için tıklayınız: Unity Temas ve Zıplama Sorunu
Şu anda (Arşiv) modunu görüntülemektesiniz. Orjinal Sürümü Görüntüle internal link
Ben unity'de yeniyim ve karakterim obje ile temas edip zıplama tuşunu bastığım anda uçmaya başlıyor. Uçmak derken gerektiğinden fazla zıplıyor bunu nasıl düzeltebilirim.
Kod:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class hareket : MonoBehaviour
{   public bool isGrounded;
   private Animator anime;
   Rigidbody rb;
   Vector3 jump;
   void Start()
   {rb = GetComponent<Rigidbody>();
   jump= new Vector3(0.0f, 2.0f, 0.0f);
       anime=GetComponent<Animator>();
   }
void OnCollisionStay()
        {
            isGrounded = true;
        }
   // Update is called once per frame
   void Update()
   {   if (Input.GetKey(KeyCode.W)){ gameObject.transform.Translate (0, 0, 0.020f);
   anime.SetBool("kos",true);}else{anime.SetBool("kos",false);}
   if (Input.GetKey(KeyCode.S))
{ gameObject.transform.Translate (0, 0, -0.020f);//geri hareket
}
if(Input.GetKey(KeyCode.A))
{ gameObject.transform.Rotate(Vector3.down);//dönderme sola
}
if(Input.GetKey(KeyCode.D))
{ gameObject.transform.Rotate(Vector3.up);//dönderme sağa
}
if(Input.GetKey(KeyCode.F)&& isGrounded==true){
rb.AddForce(jump * 8, ForceMode.Impulse);
                 isGrounded = false;


}
Debug.Log(isGrounded);
       
   }
}
Kod:
if (Input.GetKey(KeyCode.W))
bu satıran sonra karakterin yerde olup olmadığını kontrol etmelisiniz, yoksa sürekli yükselir

bu şekilde:
if(gameObject.transform.position.z==0)
     zıplama kodu
OncollisionEnter2D fonkiyonu altında ziplama gücünü ayarlayıp yerden her ayrıldığımda yani onCollisionExit2D de ziplama gücünü 0 yaparsanız hatasız ve kesin bir şekilde sorununuz çözülecektir.