27-10-2020, Saat: 09:50
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);
}
}